diff --git a/yudao-framework/yudao-spring-boot-starter-biz-weixin/src/main/java/cn/iocoder/yudao/config/WxCpConfigure.java b/yudao-framework/yudao-spring-boot-starter-biz-weixin/src/main/java/cn/iocoder/yudao/config/WxCpConfigure.java index a2d7a514..439bb9c7 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-weixin/src/main/java/cn/iocoder/yudao/config/WxCpConfigure.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-weixin/src/main/java/cn/iocoder/yudao/config/WxCpConfigure.java @@ -32,7 +32,7 @@ public class WxCpConfigure { config.setCorpId("ww17f8d10783494584"); config.setCorpSecret("i5t-rh8bXeNCgihcYPrG9ZPpWkivzPJ69sv570osk6I"); - config.setAgentId(1000036); + WxCpServiceImpl wxCpService = new WxCpServiceImpl(); wxCpService.setWxCpConfigStorage(config); diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/wxcp/WxCpMsgTypeEnum.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/wxcp/WxCpMsgTypeEnum.java new file mode 100644 index 00000000..4c46fbb2 --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/wxcp/WxCpMsgTypeEnum.java @@ -0,0 +1,15 @@ +package cn.iocoder.yudao.module.system.enums.wxcp; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum WxCpMsgTypeEnum { + + project, + + task; + + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/CpUser/dto/CpMessageDto.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/CpUser/dto/CpMessageDto.java new file mode 100644 index 00000000..8383cc02 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/CpUser/dto/CpMessageDto.java @@ -0,0 +1,44 @@ +package cn.iocoder.yudao.module.system.controller.admin.CpUser.dto; + +import cn.iocoder.yudao.module.system.enums.wxcp.WxCpMsgTypeEnum; +import io.swagger.annotations.ApiModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.Map; + +@Data +@ApiModel("企业微信发送推送消息") +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class CpMessageDto { + + private WxCpMsgTypeEnum typeEnum; + + private Long id; + + // 标题 + private String title; + + // 子标题 + private String description; + private Map contentItems; + + // 是否放大第一对item + private Boolean emphasisFirstItem; + + /** + * 用于微信消息推送的 - 模板ID 不一定适用于企业微信 + */ + private String templateId; + + /** + * 接收人userid + */ + private List reciveIds; + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/CpUser/CpUserService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/CpUser/CpUserService.java index 864664b1..eb839df9 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/CpUser/CpUserService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/CpUser/CpUserService.java @@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.system.service.CpUser; import java.util.*; import javax.validation.*; + +import cn.iocoder.yudao.module.system.controller.admin.CpUser.dto.CpMessageDto; import cn.iocoder.yudao.module.system.controller.admin.CpUser.vo.*; import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -73,4 +75,5 @@ public interface CpUserService extends IService { void cpUserSync() throws WxErrorException; + void sendMessage(CpMessageDto cpMessage) throws WxErrorException; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/CpUser/CpUserServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/CpUser/CpUserServiceImpl.java index 0b39261d..a5ff0a88 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/CpUser/CpUserServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/CpUser/CpUserServiceImpl.java @@ -1,6 +1,9 @@ package cn.iocoder.yudao.module.system.service.CpUser; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.module.system.controller.admin.CpUser.dto.CpMessageDto; +import cn.iocoder.yudao.module.system.enums.wxcp.WxCpMsgTypeEnum; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; @@ -8,6 +11,7 @@ import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.bean.WxCpDepart; import me.chanjar.weixin.cp.bean.WxCpUser; +import me.chanjar.weixin.cp.bean.message.WxCpMessage; import me.chanjar.weixin.cp.config.WxCpConfigStorage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -102,6 +106,7 @@ public class CpUserServiceImpl extends ServiceImpl implem return cpUserMapper.selectList(exportReqVO); } + public void cpUserSync() throws WxErrorException { WxCpConfigStorage config = wxCpService.getWxCpConfigStorage(); List departList = wxCpService.getDepartmentService().list(null); @@ -131,4 +136,24 @@ public class CpUserServiceImpl extends ServiceImpl implem } + + @Override + public void sendMessage(CpMessageDto cpMessage) throws WxErrorException { + WxCpMessage message = new WxCpMessage(); + String agentId = wxCpService.getWxCpConfigStorage().getAgentId().toString(); + + String page = String.format("/pages/task/%sDetail/index?id=%d", + cpMessage.getTypeEnum().equals(WxCpMsgTypeEnum.project) ? "project" : "task", + cpMessage.getId()); + + message.setMsgType("miniprogram_notice"); + message.setAppId(agentId); + message.setPage(page); + message.setTitle(cpMessage.getTitle()); + message.setDescription(cpMessage.getDescription()); + message.setContentItems(cpMessage.getContentItems()); + message.setToUser(String.join("|", cpMessage.getReciveIds())); + wxCpService.getMessageService().send(message); + } + } diff --git a/zsw-erp/src/main/java/com/zsw/erp/controller/ErpUserController.java b/zsw-erp/src/main/java/com/zsw/erp/controller/ErpUserController.java new file mode 100644 index 00000000..f95dff6d --- /dev/null +++ b/zsw-erp/src/main/java/com/zsw/erp/controller/ErpUserController.java @@ -0,0 +1,43 @@ +package com.zsw.erp.controller; + +import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; +import cn.iocoder.yudao.module.system.service.user.AdminUserService; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import io.swagger.annotations.Api; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.List; + +import static com.zsw.erp.utils.ResponseJsonUtil.returnJson; + +@RestController +@RequestMapping(value = "/user") +@Api(tags = {"系统用户信息"}) +public class ErpUserController{ + + @Resource + private AdminUserService userService; + + @GetMapping(value = "/getUserList") + public JSONArray getUserList(){ + JSONArray dataArray = new JSONArray(); + try { + List dataList = userService.getUsersByStatus(0); + if (null != dataList) { + for (AdminUserDO user : dataList) { + JSONObject item = new JSONObject(); + item.put("id", user.getId()); + item.put("userName", user.getNickname()); + dataArray.add(item); + } + } + } catch(Exception e){ + e.printStackTrace(); + } + return dataArray; + } +} diff --git a/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ErrorCodeConstants.java b/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ErrorCodeConstants.java index a0f44473..e766cf0c 100644 --- a/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ErrorCodeConstants.java +++ b/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ErrorCodeConstants.java @@ -23,6 +23,9 @@ public interface ErrorCodeConstants{ ErrorCode CROP_RECORD_NOT_EXISTS = new ErrorCode(1000007009, "农场作物出入记录不存在"); + ErrorCode TASK_CATE_NOT_EXISTS = new ErrorCode(1000007010, "任务类型不存在"); + + diff --git a/zsw-farm/zsw-farm-impl/pom.xml b/zsw-farm/zsw-farm-impl/pom.xml index 6871cdd5..2c816d72 100644 --- a/zsw-farm/zsw-farm-impl/pom.xml +++ b/zsw-farm/zsw-farm-impl/pom.xml @@ -53,6 +53,12 @@ cn.iocoder.boot yudao-spring-boot-starter-excel + + cn.iocoder.boot + yudao-module-system-impl + 1.6.2-snapshot + compile + diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/TestController.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/TestController.java new file mode 100644 index 00000000..51d8e8fc --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/TestController.java @@ -0,0 +1,44 @@ +package cn.iocoder.yudao.module.farm.controller.admin; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.system.controller.admin.CpUser.dto.CpMessageDto; +import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; +import cn.iocoder.yudao.module.system.enums.wxcp.WxCpMsgTypeEnum; +import cn.iocoder.yudao.module.system.service.CpUser.CpUserService; +import cn.iocoder.yudao.module.system.service.user.AdminUserService; +import com.google.common.collect.Maps; +import me.chanjar.weixin.common.error.WxErrorException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.HashMap; +import java.util.List; +import java.util.stream.Collectors; + +@RestController +public class TestController { + + @Autowired + private CpUserService cpUserService; + + + @GetMapping("/zyh") + public CommonResult test() throws WxErrorException { + + List users = cpUserService.list(); + CpMessageDto dto = new CpMessageDto(); + dto.setTypeEnum(WxCpMsgTypeEnum.project); + dto.setId(1L); + dto.setTitle("项目测试通知"); + HashMap map = Maps.newHashMap(); + map.put("主题","测试主题"); + map.put("时间:","2022年5月30日"); + map.put("人员:","..."); + map.put("提示:","测试消息"); + dto.setContentItems(map); + dto.setReciveIds(users.stream().map(CpUserDO::getUserId).collect(Collectors.toList())); + cpUserService.sendMessage(dto); + return CommonResult.success("okk"); + } +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/TaskCateController.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/TaskCateController.java new file mode 100644 index 00000000..9ca0b600 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/TaskCateController.java @@ -0,0 +1,100 @@ +package cn.iocoder.yudao.module.farm.controller.admin.taskCate; + +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.annotations.*; + +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.farm.controller.admin.taskCate.vo.*; +import cn.iocoder.yudao.module.farm.dal.dataobject.taskCate.TaskCateDO; +import cn.iocoder.yudao.module.farm.convert.taskCate.TaskCateConvert; +import cn.iocoder.yudao.module.farm.service.taskCate.TaskCateService; + +@Api(tags = "管理后台 - 任务类型") +@RestController +@RequestMapping("/farm/task-cate") +@Validated +public class TaskCateController { + + @Resource + private TaskCateService taskCateService; + + @PostMapping("/create") + @ApiOperation("创建任务类型") + @PreAuthorize("@ss.hasPermission('farm:task-cate:create')") + public CommonResult createTaskCate(@Valid @RequestBody TaskCateCreateReqVO createReqVO) { + return success(taskCateService.createTaskCate(createReqVO)); + } + + @PutMapping("/update") + @ApiOperation("更新任务类型") + @PreAuthorize("@ss.hasPermission('farm:task-cate:update')") + public CommonResult updateTaskCate(@Valid @RequestBody TaskCateUpdateReqVO updateReqVO) { + taskCateService.updateTaskCate(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @ApiOperation("删除任务类型") + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('farm:task-cate:delete')") + public CommonResult deleteTaskCate(@RequestParam("id") Long id) { + taskCateService.deleteTaskCate(id); + return success(true); + } + + @GetMapping("/get") + @ApiOperation("获得任务类型") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('farm:task-cate:query')") + public CommonResult getTaskCate(@RequestParam("id") Long id) { + TaskCateDO taskCate = taskCateService.getTaskCate(id); + return success(TaskCateConvert.INSTANCE.convert(taskCate)); + } + + @GetMapping("/list") + @ApiOperation("获得任务类型列表") + @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) + @PreAuthorize("@ss.hasPermission('farm:task-cate:query')") + public CommonResult> getTaskCateList(@RequestParam("ids") Collection ids) { + List list = taskCateService.getTaskCateList(ids); + return success(TaskCateConvert.INSTANCE.convertList(list)); + } + + @GetMapping("/page") + @ApiOperation("获得任务类型分页") + @PreAuthorize("@ss.hasPermission('farm:task-cate:query')") + public CommonResult> getTaskCatePage(@Valid TaskCatePageReqVO pageVO) { + PageResult pageResult = taskCateService.getTaskCatePage(pageVO); + return success(TaskCateConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/export-excel") + @ApiOperation("导出任务类型 Excel") + @PreAuthorize("@ss.hasPermission('farm:task-cate:export')") + @OperateLog(type = EXPORT) + public void exportTaskCateExcel(@Valid TaskCateExportReqVO exportReqVO, + HttpServletResponse response) throws IOException { + List list = taskCateService.getTaskCateList(exportReqVO); + // 导出 Excel + List datas = TaskCateConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, "任务类型.xls", "数据", TaskCateExcelVO.class, datas); + } + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateBaseVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateBaseVO.java new file mode 100644 index 00000000..5db426fb --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateBaseVO.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.module.farm.controller.admin.taskCate.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +/** +* 任务类型 Base VO,提供给添加、修改、详细的子 VO 使用 +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 +*/ +@Data +public class TaskCateBaseVO { + + @ApiModelProperty(value = "") + private Long parentId; + + @ApiModelProperty(value = "") + private Integer projectId; + + @ApiModelProperty(value = "", required = true) + @NotNull(message = "不能为空") + private String name; + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateCreateReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateCreateReqVO.java new file mode 100644 index 00000000..fb0498b1 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateCreateReqVO.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.farm.controller.admin.taskCate.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +@ApiModel("管理后台 - 任务类型创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class TaskCateCreateReqVO extends TaskCateBaseVO { + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateExcelVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateExcelVO.java new file mode 100644 index 00000000..1b8cabb8 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateExcelVO.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.farm.controller.admin.taskCate.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; + +import com.alibaba.excel.annotation.ExcelProperty; + +/** + * 任务类型 Excel VO + * + * @author 系统管理员 + */ +@Data +public class TaskCateExcelVO { + + @ExcelProperty("") + private Long parentId; + + @ExcelProperty("") + private Integer projectId; + + @ExcelProperty("") + private String name; + + @ExcelProperty("") + private Date createTime; + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateExportReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateExportReqVO.java new file mode 100644 index 00000000..3285bd67 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateExportReqVO.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.farm.controller.admin.taskCate.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel(value = "管理后台 - 任务类型 Excel 导出 Request VO", description = "参数和 TaskCatePageReqVO 是一致的") +@Data +public class TaskCateExportReqVO { + + @ApiModelProperty(value = "") + private Long parentId; + + @ApiModelProperty(value = "") + private Integer projectId; + + @ApiModelProperty(value = "") + private String name; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "开始") + private Date beginCreateTime; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "结束") + private Date endCreateTime; + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCatePageReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCatePageReqVO.java new file mode 100644 index 00000000..08c4120e --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCatePageReqVO.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.farm.controller.admin.taskCate.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel("管理后台 - 任务类型分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class TaskCatePageReqVO extends PageParam { + + @ApiModelProperty(value = "") + private Long parentId; + + @ApiModelProperty(value = "") + private Integer projectId; + + @ApiModelProperty(value = "") + private String name; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "开始") + private Date beginCreateTime; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "结束") + private Date endCreateTime; + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateRespVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateRespVO.java new file mode 100644 index 00000000..d3359125 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateRespVO.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.module.farm.controller.admin.taskCate.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; + +@ApiModel("管理后台 - 任务类型 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class TaskCateRespVO extends TaskCateBaseVO { + + @ApiModelProperty(value = "") + private Date createTime; + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateUpdateReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateUpdateReqVO.java new file mode 100644 index 00000000..8e984383 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateUpdateReqVO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.farm.controller.admin.taskCate.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +@ApiModel("管理后台 - 任务类型更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class TaskCateUpdateReqVO extends TaskCateBaseVO { + + @ApiModelProperty(value = "", required = true) + @NotNull(message = "不能为空") + private Long id; + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/convert/taskCate/TaskCateConvert.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/convert/taskCate/TaskCateConvert.java new file mode 100644 index 00000000..cb362b10 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/convert/taskCate/TaskCateConvert.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.farm.convert.taskCate; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import cn.iocoder.yudao.module.farm.controller.admin.taskCate.vo.*; +import cn.iocoder.yudao.module.farm.dal.dataobject.taskCate.TaskCateDO; + +/** + * 任务类型 Convert + * + * @author 系统管理员 + */ +@Mapper +public interface TaskCateConvert { + + TaskCateConvert INSTANCE = Mappers.getMapper(TaskCateConvert.class); + + TaskCateDO convert(TaskCateCreateReqVO bean); + + TaskCateDO convert(TaskCateUpdateReqVO bean); + + TaskCateRespVO convert(TaskCateDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + + List convertList02(List list); + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/taskCate/TaskCateDO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/taskCate/TaskCateDO.java new file mode 100644 index 00000000..dd542516 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/taskCate/TaskCateDO.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.module.farm.dal.dataobject.taskCate; + +import lombok.*; +import java.util.*; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 任务类型 DO + * + * @author 系统管理员 + */ +@TableName("farm_task_cate") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class TaskCateDO extends BaseDO { + + /** + * + */ + @TableId + private Long id; + /** + * + */ + private Long parentId; + /** + * + */ + private Integer projectId; + /** + * + */ + private String name; + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/mysql/taskCate/TaskCateMapper.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/mysql/taskCate/TaskCateMapper.java new file mode 100644 index 00000000..c1c888f3 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/mysql/taskCate/TaskCateMapper.java @@ -0,0 +1,38 @@ +package cn.iocoder.yudao.module.farm.dal.mysql.taskCate; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.farm.dal.dataobject.taskCate.TaskCateDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.farm.controller.admin.taskCate.vo.*; + +/** + * 任务类型 Mapper + * + * @author 系统管理员 + */ +@Mapper +public interface TaskCateMapper extends BaseMapperX { + + default PageResult selectPage(TaskCatePageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(TaskCateDO::getParentId, reqVO.getParentId()) + .eqIfPresent(TaskCateDO::getProjectId, reqVO.getProjectId()) + .likeIfPresent(TaskCateDO::getName, reqVO.getName()) + .betweenIfPresent(TaskCateDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) + .orderByDesc(TaskCateDO::getId)); + } + + default List selectList(TaskCateExportReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .eqIfPresent(TaskCateDO::getParentId, reqVO.getParentId()) + .eqIfPresent(TaskCateDO::getProjectId, reqVO.getProjectId()) + .likeIfPresent(TaskCateDO::getName, reqVO.getName()) + .betweenIfPresent(TaskCateDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) + .orderByDesc(TaskCateDO::getId)); + } + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/taskCate/TaskCateService.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/taskCate/TaskCateService.java new file mode 100644 index 00000000..60d9fa85 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/taskCate/TaskCateService.java @@ -0,0 +1,70 @@ +package cn.iocoder.yudao.module.farm.service.taskCate; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.module.farm.controller.admin.taskCate.vo.*; +import cn.iocoder.yudao.module.farm.dal.dataobject.taskCate.TaskCateDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +/** + * 任务类型 Service 接口 + * + * @author 系统管理员 + */ +public interface TaskCateService { + + /** + * 创建任务类型 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createTaskCate(@Valid TaskCateCreateReqVO createReqVO); + + /** + * 更新任务类型 + * + * @param updateReqVO 更新信息 + */ + void updateTaskCate(@Valid TaskCateUpdateReqVO updateReqVO); + + /** + * 删除任务类型 + * + * @param id 编号 + */ + void deleteTaskCate(Long id); + + /** + * 获得任务类型 + * + * @param id 编号 + * @return 任务类型 + */ + TaskCateDO getTaskCate(Long id); + + /** + * 获得任务类型列表 + * + * @param ids 编号 + * @return 任务类型列表 + */ + List getTaskCateList(Collection ids); + + /** + * 获得任务类型分页 + * + * @param pageReqVO 分页查询 + * @return 任务类型分页 + */ + PageResult getTaskCatePage(TaskCatePageReqVO pageReqVO); + + /** + * 获得任务类型列表, 用于 Excel 导出 + * + * @param exportReqVO 查询条件 + * @return 任务类型列表 + */ + List getTaskCateList(TaskCateExportReqVO exportReqVO); + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/taskCate/TaskCateServiceImpl.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/taskCate/TaskCateServiceImpl.java new file mode 100644 index 00000000..1f4b53fd --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/taskCate/TaskCateServiceImpl.java @@ -0,0 +1,82 @@ +package cn.iocoder.yudao.module.farm.service.taskCate; + +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; + +import java.util.*; +import cn.iocoder.yudao.module.farm.controller.admin.taskCate.vo.*; +import cn.iocoder.yudao.module.farm.dal.dataobject.taskCate.TaskCateDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import cn.iocoder.yudao.module.farm.convert.taskCate.TaskCateConvert; +import cn.iocoder.yudao.module.farm.dal.mysql.taskCate.TaskCateMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.farm.enums.ErrorCodeConstants.*; + +/** + * 任务类型 Service 实现类 + * + * @author 系统管理员 + */ +@Service +@Validated +public class TaskCateServiceImpl implements TaskCateService { + + @Resource + private TaskCateMapper taskCateMapper; + + @Override + public Long createTaskCate(TaskCateCreateReqVO createReqVO) { + // 插入 + TaskCateDO taskCate = TaskCateConvert.INSTANCE.convert(createReqVO); + taskCateMapper.insert(taskCate); + // 返回 + return taskCate.getId(); + } + + @Override + public void updateTaskCate(TaskCateUpdateReqVO updateReqVO) { + // 校验存在 + this.validateTaskCateExists(updateReqVO.getId()); + // 更新 + TaskCateDO updateObj = TaskCateConvert.INSTANCE.convert(updateReqVO); + taskCateMapper.updateById(updateObj); + } + + @Override + public void deleteTaskCate(Long id) { + // 校验存在 + this.validateTaskCateExists(id); + // 删除 + taskCateMapper.deleteById(id); + } + + private void validateTaskCateExists(Long id) { + if (taskCateMapper.selectById(id) == null) { + throw exception(TASK_CATE_NOT_EXISTS); + } + } + + @Override + public TaskCateDO getTaskCate(Long id) { + return taskCateMapper.selectById(id); + } + + @Override + public List getTaskCateList(Collection ids) { + return taskCateMapper.selectBatchIds(ids); + } + + @Override + public PageResult getTaskCatePage(TaskCatePageReqVO pageReqVO) { + return taskCateMapper.selectPage(pageReqVO); + } + + @Override + public List getTaskCateList(TaskCateExportReqVO exportReqVO) { + return taskCateMapper.selectList(exportReqVO); + } + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/resources/mapper/taskCate/TaskCateMapper.xml b/zsw-farm/zsw-farm-impl/src/main/resources/mapper/taskCate/TaskCateMapper.xml new file mode 100644 index 00000000..409d0e77 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/resources/mapper/taskCate/TaskCateMapper.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/zsw-farm/zsw-farm-impl/src/test/java/cn/iocoder/yudao/module/farm/service/taskCate/TaskCateServiceImplTest.java b/zsw-farm/zsw-farm-impl/src/test/java/cn/iocoder/yudao/module/farm/service/taskCate/TaskCateServiceImplTest.java new file mode 100644 index 00000000..4d5899d9 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/test/java/cn/iocoder/yudao/module/farm/service/taskCate/TaskCateServiceImplTest.java @@ -0,0 +1,175 @@ +package cn.iocoder.yudao.module.farm.service.taskCate; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.mock.mockito.MockBean; + +import javax.annotation.Resource; + +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; + +import cn.iocoder.yudao.module.farm.controller.admin.taskCate.vo.*; +import cn.iocoder.yudao.module.farm.dal.dataobject.taskCate.TaskCateDO; +import cn.iocoder.yudao.module.farm.dal.mysql.taskCate.TaskCateMapper; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import javax.annotation.Resource; +import org.springframework.context.annotation.Import; +import java.util.*; + +import static cn.hutool.core.util.RandomUtil.*; +import static cn.iocoder.yudao.module.farm.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +/** +* {@link TaskCateServiceImpl} 的单元测试类 +* +* @author 系统管理员 +*/ +@Import(TaskCateServiceImpl.class) +public class TaskCateServiceImplTest extends BaseDbUnitTest { + + @Resource + private TaskCateServiceImpl taskCateService; + + @Resource + private TaskCateMapper taskCateMapper; + + @Test + public void testCreateTaskCate_success() { + // 准备参数 + TaskCateCreateReqVO reqVO = randomPojo(TaskCateCreateReqVO.class); + + // 调用 + Long taskCateId = taskCateService.createTaskCate(reqVO); + // 断言 + assertNotNull(taskCateId); + // 校验记录的属性是否正确 + TaskCateDO taskCate = taskCateMapper.selectById(taskCateId); + assertPojoEquals(reqVO, taskCate); + } + + @Test + public void testUpdateTaskCate_success() { + // mock 数据 + TaskCateDO dbTaskCate = randomPojo(TaskCateDO.class); + taskCateMapper.insert(dbTaskCate);// @Sql: 先插入出一条存在的数据 + // 准备参数 + TaskCateUpdateReqVO reqVO = randomPojo(TaskCateUpdateReqVO.class, o -> { + o.setId(dbTaskCate.getId()); // 设置更新的 ID + }); + + // 调用 + taskCateService.updateTaskCate(reqVO); + // 校验是否更新正确 + TaskCateDO taskCate = taskCateMapper.selectById(reqVO.getId()); // 获取最新的 + assertPojoEquals(reqVO, taskCate); + } + + @Test + public void testUpdateTaskCate_notExists() { + // 准备参数 + TaskCateUpdateReqVO reqVO = randomPojo(TaskCateUpdateReqVO.class); + + // 调用, 并断言异常 + assertServiceException(() -> taskCateService.updateTaskCate(reqVO), TASK_CATE_NOT_EXISTS); + } + + @Test + public void testDeleteTaskCate_success() { + // mock 数据 + TaskCateDO dbTaskCate = randomPojo(TaskCateDO.class); + taskCateMapper.insert(dbTaskCate);// @Sql: 先插入出一条存在的数据 + // 准备参数 + Long id = dbTaskCate.getId(); + + // 调用 + taskCateService.deleteTaskCate(id); + // 校验数据不存在了 + assertNull(taskCateMapper.selectById(id)); + } + + @Test + public void testDeleteTaskCate_notExists() { + // 准备参数 + Long id = randomLongId(); + + // 调用, 并断言异常 + assertServiceException(() -> taskCateService.deleteTaskCate(id), TASK_CATE_NOT_EXISTS); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetTaskCatePage() { + // mock 数据 + TaskCateDO dbTaskCate = randomPojo(TaskCateDO.class, o -> { // 等会查询到 + o.setParentId(null); + o.setProjectId(null); + o.setName(null); + o.setCreateTime(null); + }); + taskCateMapper.insert(dbTaskCate); + // 测试 parentId 不匹配 + taskCateMapper.insert(cloneIgnoreId(dbTaskCate, o -> o.setParentId(null))); + // 测试 projectId 不匹配 + taskCateMapper.insert(cloneIgnoreId(dbTaskCate, o -> o.setProjectId(null))); + // 测试 name 不匹配 + taskCateMapper.insert(cloneIgnoreId(dbTaskCate, o -> o.setName(null))); + // 测试 createTime 不匹配 + taskCateMapper.insert(cloneIgnoreId(dbTaskCate, o -> o.setCreateTime(null))); + // 准备参数 + TaskCatePageReqVO reqVO = new TaskCatePageReqVO(); + reqVO.setParentId(null); + reqVO.setProjectId(null); + reqVO.setName(null); + reqVO.setBeginCreateTime(null); + reqVO.setEndCreateTime(null); + + // 调用 + PageResult pageResult = taskCateService.getTaskCatePage(reqVO); + // 断言 + assertEquals(1, pageResult.getTotal()); + assertEquals(1, pageResult.getList().size()); + assertPojoEquals(dbTaskCate, pageResult.getList().get(0)); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetTaskCateList() { + // mock 数据 + TaskCateDO dbTaskCate = randomPojo(TaskCateDO.class, o -> { // 等会查询到 + o.setParentId(null); + o.setProjectId(null); + o.setName(null); + o.setCreateTime(null); + }); + taskCateMapper.insert(dbTaskCate); + // 测试 parentId 不匹配 + taskCateMapper.insert(cloneIgnoreId(dbTaskCate, o -> o.setParentId(null))); + // 测试 projectId 不匹配 + taskCateMapper.insert(cloneIgnoreId(dbTaskCate, o -> o.setProjectId(null))); + // 测试 name 不匹配 + taskCateMapper.insert(cloneIgnoreId(dbTaskCate, o -> o.setName(null))); + // 测试 createTime 不匹配 + taskCateMapper.insert(cloneIgnoreId(dbTaskCate, o -> o.setCreateTime(null))); + // 准备参数 + TaskCateExportReqVO reqVO = new TaskCateExportReqVO(); + reqVO.setParentId(null); + reqVO.setProjectId(null); + reqVO.setName(null); + reqVO.setBeginCreateTime(null); + reqVO.setEndCreateTime(null); + + // 调用 + List list = taskCateService.getTaskCateList(reqVO); + // 断言 + assertEquals(1, list.size()); + assertPojoEquals(dbTaskCate, list.get(0)); + } + +} diff --git a/zsw-farm/zsw-farm-impl/src/test/resources/sql/clean.sql b/zsw-farm/zsw-farm-impl/src/test/resources/sql/clean.sql index 7c49db19..0d52703b 100644 --- a/zsw-farm/zsw-farm-impl/src/test/resources/sql/clean.sql +++ b/zsw-farm/zsw-farm-impl/src/test/resources/sql/clean.sql @@ -8,4 +8,6 @@ DELETE FROM "farm_resource"; DELETE FROM "farm_resource_type"; -DELETE FROM "farm_task"; \ No newline at end of file +DELETE FROM "farm_task"; + +DELETE FROM "farm_task_cate"; \ No newline at end of file diff --git a/zsw-farm/zsw-farm-impl/src/test/resources/sql/create_tables.sql b/zsw-farm/zsw-farm-impl/src/test/resources/sql/create_tables.sql index 16ec1149..72561b06 100644 --- a/zsw-farm/zsw-farm-impl/src/test/resources/sql/create_tables.sql +++ b/zsw-farm/zsw-farm-impl/src/test/resources/sql/create_tables.sql @@ -94,4 +94,19 @@ CREATE TABLE IF NOT EXISTS "farm_task" ( "deleted" bit NOT NULL DEFAULT FALSE, "tenant_id" bigint, PRIMARY KEY ("id") - ) COMMENT '农场任务'; \ No newline at end of file + ) COMMENT '农场任务'; + + +CREATE TABLE IF NOT EXISTS "farm_task_cate" ( + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "parent_id" bigint, + "project_id" int, + "name" varchar(255) NOT NULL, + "creator" varchar(255) DEFAULT '', + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar(255) DEFAULT '', + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + "tenant_id" bigint, + PRIMARY KEY ("id") + ) COMMENT '任务类型'; \ No newline at end of file