package mingzuozhibi.action;

import mingzuozhibi.persist.User;
import mingzuozhibi.support.Dao;
import mingzuozhibi.support.JsonArg;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController extends BaseController {

    @Autowired
    private Dao dao;

    @Transactional
    @GetMapping(value = "/api/admin/users", produces = MEDIA_TYPE)
    public String listAdminUser() {
        JSONArray array = new JSONArray();
        dao.findAll(User.class).forEach(user -> {
            array.put(user.toJSON());
        });
        return objectResult(array);
    }

    @Transactional
    @PostMapping(value = "/api/admin/users", produces = MEDIA_TYPE)
    public String saveAdminUser(
            @JsonArg("$.username") String username,
            @JsonArg("$.password") String password) {
        if (dao.lookup(User.class, "username", username) != null) {
            return errorMessage("用户名已被注册");
        }
        User user = new User(username, password);
        dao.save(user);
        return objectResult(user.toJSON());
    }

    @Transactional
    @PostMapping(value = "/api/admin/users/{id}", produces = MEDIA_TYPE)
    public String editAdminUser(
            @PathVariable("id") Long id,
            @JsonArg("$.username") String username,
            @JsonArg("$.password") String password,
            @JsonArg("$.enabled") boolean enabled) {
        User user = dao.get(User.class, id);
        user.setUsername(username);
        user.setEnabled(enabled);
        if (password != null && !password.isEmpty()) {
            user.setPassword(password);
        }
        return objectResult(user.toJSON());
    }

}

@@ -898,16 +898,200 @@
     %7D);%0A
+        if (LOGGER.isDebugEnabled()) %7B%0A            LOGGER.debug(%22%5B%7B%7D%5Dget:/api/admin/users, size=%7B%7D%22,%0A                    getWebDetails().getRemoteAddress(), array.length());%0A        %7D%0A
         
@@ -1547,16 +1547,195 @@
 (user);%0A
+        if (LOGGER.isDebugEnabled()) %7B%0A            LOGGER.debug(%22%5B%7B%7D%5Dpost:/api/admin/users: %7B%7D%22,%0A                    getWebDetails().getRemoteAddress(), user.toJSON());%0A        %7D%0A
         
@@ -2157,162 +2157,546 @@
     
-user.setUsername(username);%0A        user.setEnabled(enabled);%0A        if (password != null && !password.isEmpty()) %7B%0A            user.setPassword(password
+if (LOGGER.isDebugEnabled()) %7B%0A            LOGGER.debug(%22%5B%7B%7D%5Dpost:/api/admin/users/%7B%7D:Before:%7B%7D%22,%0A                    getWebDetails().getRemoteAddress(), id, user.toJSON());%0A        %7D%0A        user.setUsername(username);%0A        user.setEnabled(enabled);%0A        if (password != null && !password.isEmpty()) %7B%0A            user.setPassword(password);%0A        %7D%0A        if (LOGGER.isDebugEnabled()) %7B%0A            LOGGER.debug(%22%5B%7B%7D%5Dpost:/api/admin/users/%7B%7D:Modify:%7B%7D%22,%0A                    getWebDetails().getRemoteAddress(), id, user.toJSON()
 );%0A 

Update UserController Logger