Browse Source

Merge branch 'zyh' into zyj

# Conflicts:
#	zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ErrorCodeConstants.java
zyh
小久哥 3 years ago
parent
commit
80e0289e4b
  1. 2
      yudao-framework/yudao-spring-boot-starter-biz-weixin/src/main/java/cn/iocoder/yudao/config/WxCpConfigure.java
  2. 15
      yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/wxcp/WxCpMsgTypeEnum.java
  3. 44
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/CpUser/dto/CpMessageDto.java
  4. 3
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/CpUser/CpUserService.java
  5. 25
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/CpUser/CpUserServiceImpl.java
  6. 43
      zsw-erp/src/main/java/com/zsw/erp/controller/ErpUserController.java
  7. 2
      zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ErrorCodeConstants.java
  8. 6
      zsw-farm/zsw-farm-impl/pom.xml
  9. 44
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/TestController.java
  10. 100
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/TaskCateController.java
  11. 25
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateBaseVO.java
  12. 14
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateCreateReqVO.java
  13. 29
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateExcelVO.java
  14. 32
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateExportReqVO.java
  15. 34
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCatePageReqVO.java
  16. 16
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateRespVO.java
  17. 18
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/taskCate/vo/TaskCateUpdateReqVO.java
  18. 34
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/convert/taskCate/TaskCateConvert.java
  19. 40
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/taskCate/TaskCateDO.java
  20. 38
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/mysql/taskCate/TaskCateMapper.java
  21. 70
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/taskCate/TaskCateService.java
  22. 82
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/taskCate/TaskCateServiceImpl.java
  23. 12
      zsw-farm/zsw-farm-impl/src/main/resources/mapper/taskCate/TaskCateMapper.xml
  24. 175
      zsw-farm/zsw-farm-impl/src/test/java/cn/iocoder/yudao/module/farm/service/taskCate/TaskCateServiceImplTest.java
  25. 4
      zsw-farm/zsw-farm-impl/src/test/resources/sql/clean.sql
  26. 17
      zsw-farm/zsw-farm-impl/src/test/resources/sql/create_tables.sql

2
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);

15
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;
}

44
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<String,String> contentItems;
// 是否放大第一对item
private Boolean emphasisFirstItem;
/**
* 用于微信消息推送的 - 模板ID 不一定适用于企业微信
*/
private String templateId;
/**
* 接收人userid
*/
private List<String> reciveIds;
}

3
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<CpUserDO> {
void cpUserSync() throws WxErrorException;
void sendMessage(CpMessageDto cpMessage) throws WxErrorException;
}

25
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<CpUserMapper,CpUserDO> implem
return cpUserMapper.selectList(exportReqVO);
}
public void cpUserSync() throws WxErrorException {
WxCpConfigStorage config = wxCpService.getWxCpConfigStorage();
List<WxCpDepart> departList = wxCpService.getDepartmentService().list(null);
@ -131,4 +136,24 @@ public class CpUserServiceImpl extends ServiceImpl<CpUserMapper,CpUserDO> 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);
}
}

43
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<AdminUserDO> 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;
}
}

2
zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ErrorCodeConstants.java

@ -24,7 +24,7 @@ public interface ErrorCodeConstants{
ErrorCode CROP_RECORD_NOT_EXISTS = new ErrorCode(1000007009, "农场作物出入记录不存在");
ErrorCode WORK_HOUR_NOT_EXISTS = new ErrorCode(1000007010, "工时不存在");
ErrorCode TASK_CATE_NOT_EXISTS = new ErrorCode(1000007010, "任务类型不存在");
}

6
zsw-farm/zsw-farm-impl/pom.xml

@ -53,6 +53,12 @@
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-excel</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-system-impl</artifactId>
<version>1.6.2-snapshot</version>
<scope>compile</scope>
</dependency>
</dependencies>

44
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<String> test() throws WxErrorException {
List<CpUserDO> users = cpUserService.list();
CpMessageDto dto = new CpMessageDto();
dto.setTypeEnum(WxCpMsgTypeEnum.project);
dto.setId(1L);
dto.setTitle("项目测试通知");
HashMap<String,String> 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");
}
}

100
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<Long> createTaskCate(@Valid @RequestBody TaskCateCreateReqVO createReqVO) {
return success(taskCateService.createTaskCate(createReqVO));
}
@PutMapping("/update")
@ApiOperation("更新任务类型")
@PreAuthorize("@ss.hasPermission('farm:task-cate:update')")
public CommonResult<Boolean> 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<Boolean> 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<TaskCateRespVO> 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<List<TaskCateRespVO>> getTaskCateList(@RequestParam("ids") Collection<Long> ids) {
List<TaskCateDO> list = taskCateService.getTaskCateList(ids);
return success(TaskCateConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@ApiOperation("获得任务类型分页")
@PreAuthorize("@ss.hasPermission('farm:task-cate:query')")
public CommonResult<PageResult<TaskCateRespVO>> getTaskCatePage(@Valid TaskCatePageReqVO pageVO) {
PageResult<TaskCateDO> 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<TaskCateDO> list = taskCateService.getTaskCateList(exportReqVO);
// 导出 Excel
List<TaskCateExcelVO> datas = TaskCateConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "任务类型.xls", "数据", TaskCateExcelVO.class, datas);
}
}

25
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;
}

14
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 {
}

29
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;
}

32
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;
}

34
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;
}

16
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;
}

18
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;
}

34
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<TaskCateRespVO> convertList(List<TaskCateDO> list);
PageResult<TaskCateRespVO> convertPage(PageResult<TaskCateDO> page);
List<TaskCateExcelVO> convertList02(List<TaskCateDO> list);
}

40
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;
}

38
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<TaskCateDO> {
default PageResult<TaskCateDO> selectPage(TaskCatePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<TaskCateDO>()
.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<TaskCateDO> selectList(TaskCateExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<TaskCateDO>()
.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));
}
}

70
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<TaskCateDO> getTaskCateList(Collection<Long> ids);
/**
* 获得任务类型分页
*
* @param pageReqVO 分页查询
* @return 任务类型分页
*/
PageResult<TaskCateDO> getTaskCatePage(TaskCatePageReqVO pageReqVO);
/**
* 获得任务类型列表, 用于 Excel 导出
*
* @param exportReqVO 查询条件
* @return 任务类型列表
*/
List<TaskCateDO> getTaskCateList(TaskCateExportReqVO exportReqVO);
}

82
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<TaskCateDO> getTaskCateList(Collection<Long> ids) {
return taskCateMapper.selectBatchIds(ids);
}
@Override
public PageResult<TaskCateDO> getTaskCatePage(TaskCatePageReqVO pageReqVO) {
return taskCateMapper.selectPage(pageReqVO);
}
@Override
public List<TaskCateDO> getTaskCateList(TaskCateExportReqVO exportReqVO) {
return taskCateMapper.selectList(exportReqVO);
}
}

12
zsw-farm/zsw-farm-impl/src/main/resources/mapper/taskCate/TaskCateMapper.xml

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.farm.dal.mysql.taskCate.TaskCateMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

175
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<TaskCateDO> 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<TaskCateDO> list = taskCateService.getTaskCateList(reqVO);
// 断言
assertEquals(1, list.size());
assertPojoEquals(dbTaskCate, list.get(0));
}
}

4
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";
DELETE FROM "farm_task";
DELETE FROM "farm_task_cate";

17
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 '农场任务';
) 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 '任务类型';
Loading…
Cancel
Save