diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/YudaoMybatisAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/YudaoMybatisAutoConfiguration.java index 5d0508e2..6d9bcb8c 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/YudaoMybatisAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/YudaoMybatisAutoConfiguration.java @@ -42,7 +42,7 @@ import java.util.Map; @MapperScans({ @MapperScan(basePackages ={"co.yixiang.**.service.mapper", "co.yixiang.config"},sqlSessionFactoryRef = "shangcheng"), @MapperScan(basePackages = {"com.zsw.erp.datasource.mappers"},sqlSessionFactoryRef = "erp"), - @MapperScan(value = "${yudao.info.base-package}", annotationClass = Mapper.class, + @MapperScan(basePackages = {"${yudao.info.base-package}", "cn.iocoder.yudao"}, annotationClass = Mapper.class, lazyInitialization = "${mybatis.lazy-initialization:false}") // Mapper 懒加载,目前仅用于单元测试 }) @Configuration diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/handler/ListIntToListLongTypeHandler.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/handler/ListIntToListLongTypeHandler.java new file mode 100644 index 00000000..8e085466 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/handler/ListIntToListLongTypeHandler.java @@ -0,0 +1,68 @@ +package cn.iocoder.yudao.framework.mybatis.core.handler; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.json.JSONUtil; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.CollectionType; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; +import org.apache.ibatis.type.MappedJdbcTypes; +import org.apache.ibatis.type.MappedTypes; + + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +/** + * zyj + */ +@MappedJdbcTypes(JdbcType.VARCHAR) // 数据库中该字段存储的类型 +@MappedTypes(List.class) // 需要转换的对象 +public class ListIntToListLongTypeHandler extends BaseTypeHandler> { + + private static ObjectMapper mObjectMapper = new ObjectMapper(); + + @Override + public void setNonNullParameter(PreparedStatement preparedStatement, int i, List longs, JdbcType jdbcType) throws SQLException { + String json = JSONUtil.toJsonStr(longs); + preparedStatement.setObject(i, json); + } + + @Override + public List getNullableResult(ResultSet resultSet, String columnName) throws SQLException { + String value = resultSet.getString(columnName); + return getLongs(value); + } + + + @Override + public List getNullableResult(ResultSet resultSet, int i) throws SQLException { + String value = resultSet.getString(i); + return getLongs(value); + } + + @Override + public List getNullableResult(CallableStatement callableStatement, int i) throws SQLException { + String value = callableStatement.getString(i); + return getLongs(value); + } + + private List getLongs(String value) { + if (ObjectUtil.isNotEmpty(value)) { + try { + CollectionType type = mObjectMapper.getTypeFactory().constructCollectionType(ArrayList.class, Long.class); + List longs = mObjectMapper.readValue(value , type); + return longs; + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + } + return null; + } +} + diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dict/DictAspect.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dict/DictAspect.java index e4db1565..cdcb8862 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dict/DictAspect.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dict/DictAspect.java @@ -1,9 +1,11 @@ package cn.iocoder.yudao.module.system.dict; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.json.JSONUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.service.dict.DictDataService; +import com.alibaba.druid.support.json.JSONUtils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.parser.Feature; @@ -97,13 +99,15 @@ public class DictAspect { for (Object record : ((PageResult) ((CommonResult) result).getData()).getList()) { ObjectMapper mapper = new ObjectMapper(); - String json="{}"; - try { - //解决@JsonFormat注解解析不了的问题详见SysAnnouncement类的@JsonFormat - json = mapper.writeValueAsString(record); - } catch (JsonProcessingException e) { - log.error("json解析失败"+e.getMessage(),e); - } +// 1String json="{}"; + String json = JSONUtil.toJsonStr(record); + +// try { +// //解决@JsonFormat注解解析不了的问题详见SysAnnouncement类的@JsonFormat +// json = mapper.writeValueAsString(record); +// } catch (JsonProcessingException e) { +// log.error("json解析失败"+e.getMessage(),e); +// } //update-begin--Author:scott -- Date:20211223 ----for:【issues/3303】restcontroller返回json数据后key顺序错乱 ----- JSONObject item = JSONObject.parseObject(json, Feature.OrderedField); //update-end--Author:scott -- Date:20211223 ----for:【issues/3303】restcontroller返回json数据后key顺序错乱 ----- diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsg.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsg.java index c758a9b7..0703906f 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsg.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsg.java @@ -11,9 +11,9 @@ import java.lang.annotation.*; @Documented public @interface FarmMsg { - FarmMsgType type() default FarmMsgType.NONE; + FarmMsgTypeEnum type() default FarmMsgTypeEnum.NONE; - FarmMsgType operation() default FarmMsgType.NONE; + FarmMsgTypeEnum operation() default FarmMsgTypeEnum.NONE; String title() default ""; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgAspect.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgAspect.java index fc7b0ea9..2a971e6d 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgAspect.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgAspect.java @@ -2,34 +2,39 @@ package cn.iocoder.yudao.module.farm.annotation; -import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.farm.annotation.FarmMsg; import cn.iocoder.yudao.module.farm.controller.admin.project.vo.ProjectCreateReqVO; import cn.iocoder.yudao.module.farm.controller.admin.project.vo.ProjectRespVO; import cn.iocoder.yudao.module.farm.controller.admin.project.vo.ProjectUpdateReqVO; import cn.iocoder.yudao.module.farm.controller.admin.task.vo.TaskCreateReqVO; import cn.iocoder.yudao.module.farm.controller.admin.task.vo.TaskRespVO; import cn.iocoder.yudao.module.farm.controller.admin.task.vo.TaskUpdateReqVO; -import cn.iocoder.yudao.module.farm.dal.dataobject.logMsg.LogMsgDO; +import cn.iocoder.yudao.module.farm.dal.dataobject.discuss.DiscussDO; import cn.iocoder.yudao.module.farm.dal.dataobject.project.ProjectDO; import cn.iocoder.yudao.module.farm.dal.dataobject.task.TaskDO; import cn.iocoder.yudao.module.farm.dal.dataobject.taskCate.TaskCateDO; +import cn.iocoder.yudao.module.farm.dal.mysql.discuss.DiscussMapper; import cn.iocoder.yudao.module.farm.dal.mysql.logMsg.LogMsgMapper; import cn.iocoder.yudao.module.farm.dal.mysql.project.ProjectMapper; +import cn.iocoder.yudao.module.farm.dal.mysql.task.TaskMapper; import cn.iocoder.yudao.module.farm.dal.mysql.taskCate.TaskCateMapper; import cn.iocoder.yudao.module.farm.service.WxCpServiceNoticeService; +import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; +import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; +import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper; +import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper; import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.cp.api.WxCpMessageService; import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.bean.message.WxCpMessage; -import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.*; import org.aspectj.lang.reflect.MethodSignature; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @@ -47,11 +52,19 @@ public class FarmMsgAspect { private TaskCateMapper taskCateMapper; @Resource private ProjectMapper projectMapper; + @Resource + private DiscussMapper discussMapper; + @Resource + private TaskMapper taskMapper; + @Resource + private CpUserMapper cpUserMapper; + @Resource + private AdminUserMapper adminUserMapper; @Resource private WxCpServiceNoticeService wxCpServiceNoticeService; - @Autowired + @Resource private WxCpService wxCpService; /** @@ -67,8 +80,8 @@ public class FarmMsgAspect { Object object = pjp.proceed(); if (object instanceof CommonResult){ // 只处理接口正常result - if (farmMsg.type() == FarmMsgType.NONE - || farmMsg.operation() == FarmMsgType.NONE + if (farmMsg.type() == FarmMsgTypeEnum.NONE + || farmMsg.operation() == FarmMsgTypeEnum.NONE || ((CommonResult) object).getCode()!=0 ){ return object; } @@ -76,15 +89,55 @@ public class FarmMsgAspect { // 构造一个企业推送消息 WxCpMessage message = new WxCpMessage(); - if (farmMsg.type() == FarmMsgType.PROJECT){ - if (farmMsg.operation() == FarmMsgType.CREATE){ + if (farmMsg.type() == FarmMsgTypeEnum.PROJECT){ + if (farmMsg.operation() == FarmMsgTypeEnum.CREATE){ Long id = (Long) ((CommonResult) object).getData(); + + //处理所需要数据 + MethodSignature signature = (MethodSignature) pjp.getSignature(); + Method method = signature.getMethod(); + FarmMsgDTO farmMsgDTO = this.assembleMsg(method, pjp.getArgs(), (CommonResult) object); + + //接受消息的人 + String toUserStr = this.assembleCpUserId(farmMsg.type(), id); + //发起人 + AdminUserDO adminUser = adminUserMapper.selectOne(AdminUserDO::getId, getLoginUserId()); + CpUserDO user = cpUserMapper.selectOne(CpUserDO::getUserId, adminUser.getCpUserId()); + StringBuilder description = new StringBuilder() + .append(user.getName()) + .append(" ") + .append(farmMsgDTO.getOperation().getDesc()) + .append(farmMsgDTO.getType().getDesc()) + .append(":") + .append(farmMsgDTO.getTitle()) + .append("(其中有你)"); + + + if (!toUserStr.contains("WeiLaiKeQi")){ + return object; + } + + // 发企业微信 - // 拼接全部的参与用户 - message.setToUser(""); - //把主题填充 - message.setTitle(""); - wxCpService.getMessageService().send(message); + WxCpMessageService wxCpMessageService = wxCpService.getMessageService(); + + //消息类型 必填 此处固定为 文本卡片 + message.setMsgType("textcard"); + //企业应用id 必填 + message.setAgentId(wxCpService.getWxCpConfigStorage().getAgentId()); + //消息标题 必填 + message.setTitle("回乡农场任务管理更新"); + //消息描述 必填 + message.setDescription(description.toString()); + //点击后跳转链接 必填 + message.setUrl("https://www.baidu.com"); + + //接受消息成员 选填 + message.setToUser(toUserStr); + +// WxCpMessageSendResult result = wxCpMessageService.send(message); +// log.info("企业微信消息发送结果:{}",result); + System.out.println(message); } // 跟新项目 删除项目 更新任务 删除任务。。。 @@ -100,107 +153,95 @@ public class FarmMsgAspect { return object; } -// @Before(value = "farmMsgPointCut()") -// public void beforeSaveFarmMsg(JoinPoint joinPoint){ -// MethodSignature signature = (MethodSignature) joinPoint.getSignature(); -// Method method = signature.getMethod(); -// FarmMsg farmMsg = method.getAnnotation(FarmMsg.class); -// -// if (method.getName().startsWith("get")){ -// if (farmMsg.type().equals("任务")){ -// -// }else if (farmMsg.type().equals("项目")){ -// -// } -// } -// -// } - /** - * 拦截用户操作日志, 连接点执行完成后记录, 如果连接点异常,则不会执行 - * @param jointPoint 切入点 + * @Description 获取需要接受信息的成员 + * @param id 可能是 projectId taskId 或 discussId **/ + public String assembleCpUserId(FarmMsgTypeEnum farmMsgType, Long id){ + List idList = new ArrayList<>(); + if (farmMsgType.equals(FarmMsgTypeEnum.PROJECT)){ + ProjectDO project = projectMapper.selectOne(ProjectDO::getId, id); + idList.addAll(project.getMembers().toJavaList(Long.class)); + }else if (farmMsgType.equals(FarmMsgTypeEnum.TASK)){ + TaskDO task = taskMapper.selectOne(TaskDO::getId, id); + idList.add(task.getMainPerson()); + idList.addAll(task.getExecutorPerson().toJavaList(Long.class)); + }else if (farmMsgType.equals(FarmMsgTypeEnum.DISCUSS)){ + DiscussDO discuss = discussMapper.selectOne(DiscussDO::getId, id); + TaskDO task = taskMapper.selectOne(TaskDO::getId, discuss.getId()); + idList.add(task.getMainPerson()); + idList.addAll(task.getExecutorPerson().toJavaList(Long.class)); + } + + StringBuilder builder = new StringBuilder(); + List userList = cpUserMapper.selectList(CpUserDO::getId, idList); + userList.forEach(user ->{ + builder.append(user.getUserId()).append("|"); + }); + return builder.toString().substring(0, builder.length() -1); + } + + + public FarmMsgDTO assembleMsg(Method method, Object[] objects, Object result){ + String title = ""; + String msg = ""; -// @AfterReturning(value = "farmMsgPointCut()", returning = "result") -// public void afterSaveFarmMsg(JoinPoint jointPoint, Object result){ -// //从切入点通过反射获取切入点方法 -// MethodSignature signature = (MethodSignature) jointPoint.getSignature(); -// //获取切入点的方法 -// Method method = signature.getMethod(); -// -// FarmMsgDTO farmMsgDTO = this.assembleMsg(method, jointPoint.getArgs(), result); -// -// //插入农场日志信息 -// LogMsgDO logMsg = LogMsgDO.builder() -// .type(farmMsgDTO.getType()) -// .operation(farmMsgDTO.getOperation()) -// .title(farmMsgDTO.getTitle()) -// .msg(farmMsgDTO.getMsg()) -// .userId(getLoginUserId()) -// .build(); -// logMsgMapper.insert(logMsg); -// } - -// public FarmMsgDTO assembleMsg(Method method, Object[] objects, Object result){ -// String title = ""; -// String msg = ""; -// -// FarmMsg farmMsg = method.getAnnotation(FarmMsg.class); -// if (method.getName().startsWith("get")){ -// for (Object object : objects) { -// log.info("after用户{},{},{},{}",getLoginUserId(), farmMsg.type(), farmMsg.title(), object); -// if (farmMsg.type().equals("项目")){ -// CommonResult projectDO = (CommonResult) result; -// title = projectDO.getData().getName(); -// } -// if (farmMsg.type().equals("任务")){ -// CommonResult taskDO = (CommonResult) result; -// ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getData().getProjectId()); -// TaskCateDO taskCate = taskCateMapper.selectOne(TaskCateDO::getId, taskDO.getData().getTaskCateId()); -// title = project.getName(); -// msg = taskCate.getName(); -// } -// } -// } -// -// if (method.getName().startsWith("update")){ -// for (Object object : objects) { -// if (farmMsg.type().equals("项目")){ -// ProjectUpdateReqVO projectDO = (ProjectUpdateReqVO) object; -// title = projectDO.getName(); -// } -// if (farmMsg.type().equals("任务")){ -// TaskUpdateReqVO taskDO = (TaskUpdateReqVO) object; -// ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getProjectId()); -// title = project.getName(); -// TaskCateDO taskCate = taskCateMapper.selectOne(TaskCateDO::getId, taskDO.getTaskCateId()); -// msg = taskCate.getName(); -// } -// } -// } -// -// if (method.getName().startsWith("create")){ -// for (Object object : objects){ -// if (farmMsg.type().equals("项目")){ -// ProjectCreateReqVO projectDO = (ProjectCreateReqVO) object; -// title = projectDO.getName(); -// } -// if (farmMsg.type().equals("任务")){ -// TaskCreateReqVO taskDO = (TaskCreateReqVO) object; -// ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getProjectId()); -// title = project.getName(); -// TaskCateDO taskCate = taskCateMapper.selectOne(TaskCateDO::getId, taskDO.getTaskCateId()); -// msg = taskCate.getName(); -// } -// } -// } -// -// FarmMsgDTO farmMsgDTO = FarmMsgDTO.builder() -// .type(farmMsg.type()) -// .operation(farmMsg.operation()) -// .title(title) -// .msg(msg).build(); -// return farmMsgDTO; -// } + FarmMsg farmMsg = method.getAnnotation(FarmMsg.class); + if (method.getName().startsWith("get")){ + for (Object object : objects) { + log.info("after用户{},{},{},{}",getLoginUserId(), farmMsg.type(), farmMsg.title(), object); + if (farmMsg.type().equals(FarmMsgTypeEnum.PROJECT)){ + CommonResult projectDO = (CommonResult) result; + title = projectDO.getData().getName(); + } + if (farmMsg.type().equals(FarmMsgTypeEnum.TASK)){ + CommonResult taskDO = (CommonResult) result; + ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getData().getProjectId()); + TaskCateDO taskCate = taskCateMapper.selectOne(TaskCateDO::getId, taskDO.getData().getTaskCateId()); + title = project.getName(); + msg = taskCate.getName(); + } + } + } + + if (method.getName().startsWith("update")){ + for (Object object : objects) { + if (farmMsg.type().equals(FarmMsgTypeEnum.PROJECT)){ + ProjectUpdateReqVO projectDO = (ProjectUpdateReqVO) object; + title = projectDO.getName(); + } + if (farmMsg.type().equals(FarmMsgTypeEnum.TASK)){ + TaskUpdateReqVO taskDO = (TaskUpdateReqVO) object; + ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getProjectId()); + title = project.getName(); + TaskCateDO taskCate = taskCateMapper.selectOne(TaskCateDO::getId, taskDO.getTaskCateId()); + msg = taskCate.getName(); + } + } + } + + if (method.getName().startsWith("create")){ + for (Object object : objects){ + if (farmMsg.type().equals(FarmMsgTypeEnum.PROJECT)){ + ProjectCreateReqVO projectDO = (ProjectCreateReqVO) object; + title = projectDO.getName(); + } + if (farmMsg.type().equals(FarmMsgTypeEnum.TASK)){ + TaskCreateReqVO taskDO = (TaskCreateReqVO) object; + ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getProjectId()); + title = project.getName(); + TaskCateDO taskCate = taskCateMapper.selectOne(TaskCateDO::getId, taskDO.getTaskCateId()); + msg = taskCate.getName(); + } + } + } + + FarmMsgDTO farmMsgDTO = FarmMsgDTO.builder() + .type(FarmMsgTypeEnum.getDescBtType(farmMsg.type())) + .operation(FarmMsgTypeEnum.getDescBtType(farmMsg.operation())) + .title(title) + .msg(msg).build(); + return farmMsgDTO; + } } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgDTO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgDTO.java index 92353e2e..4da2e206 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgDTO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgDTO.java @@ -10,9 +10,9 @@ import lombok.Data; @Builder public class FarmMsgDTO { - private String type; + private FarmMsgTypeEnum type; - private String operation; + private FarmMsgTypeEnum operation; private String title; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgType.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgType.java deleted file mode 100644 index b51ad2f7..00000000 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgType.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.farm.annotation; - -import lombok.Getter; - -@Getter -public enum FarmMsgType { - - PROJECT, - TASK, - DISCUSS, - - - CREATE, - UPDATE, - SELECT, - EDIT, - DELETE, - - NONE; -} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgTypeEnum.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgTypeEnum.java new file mode 100644 index 00000000..664c8d1b --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgTypeEnum.java @@ -0,0 +1,36 @@ +package cn.iocoder.yudao.module.farm.annotation; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.stream.Stream; + +@Getter +@AllArgsConstructor +public enum FarmMsgTypeEnum { + + PROJECT("项目"), + TASK("任务"), + DISCUSS("活动"), + + + CREATE("创建"), + UPDATE("更新"), + SELECT("查看"), + EDIT("编辑"), + DELETE("删除"), + + NONE("无意义"); + + /** + * 条件 + */ + private final String desc; + + public static FarmMsgTypeEnum getDescBtType(FarmMsgTypeEnum msgType) { + return Stream.of(FarmMsgTypeEnum.values()) + .filter(p -> p.equals(msgType)) + .findAny() + .orElse(null); + } +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussBaseVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussBaseVO.java index 24e9c945..c3885d2c 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussBaseVO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussBaseVO.java @@ -30,7 +30,7 @@ public class DiscussBaseVO { @ApiModelProperty(value = "") private List images; - private JSONArray areas; + private List areas; private Integer cropNum; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussExcelVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussExcelVO.java index 0677f436..71eed14d 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussExcelVO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussExcelVO.java @@ -33,7 +33,7 @@ public class DiscussExcelVO { @ExcelProperty("") private List images; - private JSONArray areas; + private List areas; private Integer cropNum; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussExportReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussExportReqVO.java index 50d1ea15..11b5566c 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussExportReqVO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussExportReqVO.java @@ -25,7 +25,7 @@ public class DiscussExportReqVO { @ApiModelProperty(value = "") private String images; - private JSONArray areas; + private List areas; private Integer cropNum; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussPageReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussPageReqVO.java index bab5f2bf..2940ea89 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussPageReqVO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussPageReqVO.java @@ -27,7 +27,7 @@ public class DiscussPageReqVO extends PageParam { @ApiModelProperty(value = "") private String images; - private JSONArray areas; + private List areas; private Integer cropNum; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/ProjectController.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/ProjectController.java index 6b9846bb..cce85488 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/ProjectController.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/ProjectController.java @@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.farm.controller.admin.project; import cn.iocoder.yudao.framework.common.page.PageVO; import cn.iocoder.yudao.module.farm.annotation.FarmMsg; -import cn.iocoder.yudao.module.farm.annotation.FarmMsgType; +import cn.iocoder.yudao.module.farm.annotation.FarmMsgTypeEnum; import cn.iocoder.yudao.module.farm.controller.admin.project.dto.ProjectListDTO; import cn.iocoder.yudao.module.farm.controller.admin.project.dto.ProjectPageDTO; import com.zsw.base.R; @@ -40,7 +40,7 @@ public class ProjectController { @Resource private ProjectService projectService; - @FarmMsg(type = FarmMsgType.PROJECT, operation = FarmMsgType.CREATE) + @FarmMsg(type = FarmMsgTypeEnum.PROJECT, operation = FarmMsgTypeEnum.CREATE) @PostMapping("/create") @ApiOperation("创建农场项目") @PreAuthorize("@ss.hasPermission('farm:project:create')") @@ -48,7 +48,7 @@ public class ProjectController { return success(projectService.createProject(createReqVO)); } - @FarmMsg(type = FarmMsgType.PROJECT, operation = FarmMsgType.UPDATE) + @FarmMsg(type = FarmMsgTypeEnum.PROJECT, operation = FarmMsgTypeEnum.UPDATE) @PutMapping("/update") @ApiOperation("更新农场项目") @PreAuthorize("@ss.hasPermission('farm:project:update')") @@ -57,7 +57,7 @@ public class ProjectController { return success(true); } - @FarmMsg(type = FarmMsgType.PROJECT,operation = FarmMsgType.DELETE) + @FarmMsg(type = FarmMsgTypeEnum.PROJECT,operation = FarmMsgTypeEnum.DELETE) @DeleteMapping("/delete") @ApiOperation("删除农场项目") @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java index f1f7c1f7..b2c54515 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.farm.controller.admin.task; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.NumberUtil; import cn.iocoder.yudao.framework.common.page.PageVO; import cn.iocoder.yudao.module.farm.annotation.FarmMsg; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/discuss/DiscussDO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/discuss/DiscussDO.java index 0e2b807c..ceee02bb 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/discuss/DiscussDO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/discuss/DiscussDO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.farm.dal.dataobject.discuss; +import cn.iocoder.yudao.framework.mybatis.core.handler.ListIntToListLongTypeHandler; import cn.iocoder.yudao.module.farm.controller.admin.workHour.vo.WorkHourBaseVO; import cn.iocoder.yudao.module.farm.dal.dataobject.workHour.WorkHourDO; import com.alibaba.fastjson.JSONArray; @@ -51,8 +52,8 @@ public class DiscussDO extends BaseDO { @TableField(typeHandler = JacksonTypeHandler.class) private List images; - @TableField(typeHandler = JacksonTypeHandler.class) - private JSONArray areas; + @TableField(typeHandler = ListIntToListLongTypeHandler.class) + private List areas; private Integer cropNum; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/task/TaskDO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/task/TaskDO.java index 947a897c..064e06a7 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/task/TaskDO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/task/TaskDO.java @@ -1,14 +1,19 @@ package cn.iocoder.yudao.module.farm.dal.dataobject.task; +import cn.iocoder.yudao.framework.mybatis.core.handler.ListIntToListLongTypeHandler; import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler; import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import io.swagger.annotations.ApiModelProperty; import cn.iocoder.yudao.module.farm.enums.TaskStatus; import lombok.*; + +import java.sql.JDBCType; +import java.sql.Types; import java.util.*; import com.baomidou.mybatisplus.annotation.*; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import org.apache.ibatis.type.JdbcType; /** * 农场项目 DO @@ -53,7 +58,7 @@ public class TaskDO extends BaseDO { @TableField(typeHandler = JacksonTypeHandler.class) private JSONArray resources; @ApiModelProperty("子区域") - @TableField(typeHandler = JacksonTypeHandler.class) + @TableField(typeHandler = ListIntToListLongTypeHandler.class) private List areas; @ApiModelProperty("任务图片") diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaService.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaService.java index 15663f41..bc0cb7da 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaService.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaService.java @@ -72,6 +72,6 @@ public interface AreaService { /** * 根据区域 返回区域信息List **/ - public List findAreaName(List areaList, JSONArray areaArray); + List findAreaName(List areaList, List areaArray); } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaServiceImpl.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaServiceImpl.java index 9d1e6f50..619fa862 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaServiceImpl.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaServiceImpl.java @@ -92,28 +92,23 @@ public class AreaServiceImpl implements AreaService { /** * 根据区域 返回区域信息List **/ - public List findAreaName(List areaList, JSONArray areaArray){ + public List findAreaName(List areaList, List areaArray){ List areaNameList = new ArrayList<>(); - JSONArray array = JSONArray.parseArray(areaArray.toString()); - for (Object selectArea : array) { - JSONArray array123 = JSONArray.parseArray(JSON.toJSONString( selectArea)); - Long areaParent = Long.valueOf(String.valueOf(array123.get(0))); - Long areaSon = Long.valueOf(String.valueOf(array123.get(1))); - StringBuilder areaName = new StringBuilder(); + for (Long aLong : areaArray) { for (AreaDO areaDO : areaList) { - if (areaDO.getId().equals(areaParent)){ - areaName.append(areaDO.getName()); + if (areaDO.getId().equals(aLong)){ + //拿到二级区域 + areaList.stream().filter(parentArea -> parentArea.getId().equals(areaDO.getParentId())).findFirst().ifPresent( + p ->{ + //在拿到一级区域 + StringBuilder areaName = new StringBuilder().append(p.getName()).append(":").append(areaDO.getName()); + areaNameList.add(areaName.toString()); + } + ); } - if (areaDO.getId().equals(areaSon)){ - areaName.append(areaDO.getName()); - } - } - if (ObjectUtil.isNotEmpty(areaName)){ - areaNameList.add(areaName.toString()); } } return areaNameList; - } } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/discuss/DiscussServiceImpl.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/discuss/DiscussServiceImpl.java index dfe6aea7..354439da 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/discuss/DiscussServiceImpl.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/discuss/DiscussServiceImpl.java @@ -95,7 +95,12 @@ public class DiscussServiceImpl implements DiscussService { //插入工时记录 workHourMapper.insertBatch(workSaveList); //更新员工工时合计 - cpUserService.updateBatchById(userList); + //todo service有问题 +// cpUserService.updateBatchById(userList); + userList.stream().forEach(item ->{ + cpUserMapper.updateById(item); + }); + } // 返回 diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java index 75ef21b4..802dbfa8 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java @@ -188,11 +188,14 @@ public class TaskServiceImpl implements TaskService { List discussDOList = discussMapper.selectList(DiscussDO::getTaskId, id); taskMsg.setCumulativeQuantity(ObjectUtil.isEmpty(discussDOList) ? 0 : discussDOList.stream().mapToInt(DiscussDO::getCropNum).sum()); //已选择的二级区域 - List secondAreaList = areaMapper.selectList(AreaDO::getId, taskDO.getAreas()); - taskMsg.setSecondAreaList(secondAreaList); - List parendIdList = secondAreaList.stream().map(AreaDO::getParentId).collect(Collectors.toList()); - List firstAreaList = areaMapper.selectList(AreaDO::getId, parendIdList); - taskMsg.setFirstAreaList(firstAreaList); + if (ObjectUtil.isNotEmpty(taskDO.getAreas())){ + List secondAreaList = areaMapper.selectList(AreaDO::getId, taskDO.getAreas()); + taskMsg.setSecondAreaList(secondAreaList); + List parendIdList = secondAreaList.stream().map(AreaDO::getParentId).collect(Collectors.toList()); + List firstAreaList = areaMapper.selectList(AreaDO::getId, parendIdList); + taskMsg.setFirstAreaList(firstAreaList); + } + return R.success(taskMsg); }