|
@@ -0,0 +1,118 @@
|
|
|
+package com.management.platform.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.management.platform.entity.User;
|
|
|
+import com.management.platform.entity.UserDateAllow;
|
|
|
+import com.management.platform.mapper.UserMapper;
|
|
|
+import com.management.platform.service.UserDateAllowService;
|
|
|
+import com.management.platform.util.HttpRespMsg;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 前端控制器
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author Seyason
|
|
|
+ * @since 2025-10-14
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/user-date-allow")
|
|
|
+public class UserDateAllowController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserDateAllowService userDateAllowService;
|
|
|
+ @Resource
|
|
|
+ private UserMapper userMapper;
|
|
|
+ @Resource
|
|
|
+ private HttpServletRequest request;
|
|
|
+
|
|
|
+ @RequestMapping("/userDateAllow")
|
|
|
+ public HttpRespMsg userDateAllow(UserDateAllow userDateAllow){
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
|
|
|
+ int count;
|
|
|
+ if(userDateAllow.getId() == null){
|
|
|
+ count = userDateAllowService.count(new LambdaQueryWrapper<UserDateAllow>()
|
|
|
+ .eq(UserDateAllow::getCompanyId, companyId)
|
|
|
+ .eq(UserDateAllow::getDate, userDateAllow.getDate())
|
|
|
+ .eq(UserDateAllow::getUserId, userDateAllow.getUserId()));
|
|
|
+ } else {
|
|
|
+ count = userDateAllowService.count(new LambdaQueryWrapper<UserDateAllow>()
|
|
|
+ .eq(UserDateAllow::getCompanyId, companyId)
|
|
|
+ .ne(UserDateAllow::getId, userDateAllow.getId())
|
|
|
+ .eq(UserDateAllow::getDate, userDateAllow.getDate())
|
|
|
+ .eq(UserDateAllow::getUserId, userDateAllow.getUserId()));
|
|
|
+ }
|
|
|
+ if(count > 0){
|
|
|
+ msg.setError("该用户在当前日期已存在允许记录,请重新选择");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ userDateAllow.setCompanyId(companyId);
|
|
|
+ if(!userDateAllowService.saveOrUpdate(userDateAllow)){
|
|
|
+ msg.setError("验证失败");
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/list")
|
|
|
+ public HttpRespMsg list(){
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
|
|
|
+ List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getCompanyId, companyId));
|
|
|
+ List<UserDateAllow> userDateAllows = userDateAllowService.list(new LambdaQueryWrapper<UserDateAllow>().eq(UserDateAllow::getCompanyId, companyId));
|
|
|
+
|
|
|
+ // 创建用户ID到用户名的映射
|
|
|
+ Map<String, String> userIdToNameMap = userList.stream()
|
|
|
+ .collect(Collectors.toMap(User::getId, User::getName, (existing, replacement) -> existing));
|
|
|
+
|
|
|
+ // 为每个UserDateAllow设置用户名
|
|
|
+ userDateAllows.forEach(u -> {
|
|
|
+ String userName = userIdToNameMap.get(u.getUserId());
|
|
|
+ if(userName != null){
|
|
|
+ u.setUserName(userName);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ msg.setData(userDateAllows);
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/delete")
|
|
|
+ public HttpRespMsg delete(Integer id){
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ if(!userDateAllowService.removeById(id)){
|
|
|
+ msg.setError("验证失败");
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/listByUser")
|
|
|
+ public HttpRespMsg listByUser(String userId){
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
|
|
|
+ List<UserDateAllow> userDateAllows = userDateAllowService.list(new LambdaQueryWrapper<UserDateAllow>()
|
|
|
+ .eq(UserDateAllow::getCompanyId, companyId)
|
|
|
+ .eq(UserDateAllow::getUserId, userId));
|
|
|
+ msg.setData(userDateAllows);
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/listByDate")
|
|
|
+ public HttpRespMsg listByDate(String date){
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
|
|
|
+ List<UserDateAllow> userDateAllows = userDateAllowService.list(new LambdaQueryWrapper<UserDateAllow>()
|
|
|
+ .eq(UserDateAllow::getCompanyId, companyId)
|
|
|
+ .eq(UserDateAllow::getDate, date));
|
|
|
+ msg.setData(userDateAllows);
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+}
|