From 5998b4a846be4dfc95c366d46f8d5865988bdd10 Mon Sep 17 00:00:00 2001 From: zhaiqm <1132477033@qq.com> Date: Fri, 1 Sep 2023 08:38:18 +0800 Subject: [PATCH] =?UTF-8?q?@=E4=BD=9C=E4=B8=9A=E5=8C=BA=E5=9F=9F=E7=AE=A1?= =?UTF-8?q?=E7=90=86@=E7=BF=9F=E5=8D=83=E6=B0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../safeproduct/workarea/entity/WorkArea.java | 54 +++++++++++++ .../safeproduct/workarea/vo/WorkAreaQueryVo.java | 32 ++++++++ .../workarea/controller/WorkAreaController.java | 63 +++++++++++++++ .../workarea/mapper/WorkAreaMapper.java | 7 ++ .../workarea/service/WorkAreaService.java | 22 +++++ .../workarea/service/impl/WorkAreaServiceImpl.java | 93 ++++++++++++++++++++++ 6 files changed, 271 insertions(+) create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/workarea/entity/WorkArea.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/workarea/vo/WorkAreaQueryVo.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/controller/WorkAreaController.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/mapper/WorkAreaMapper.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/service/WorkAreaService.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/service/impl/WorkAreaServiceImpl.java diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/workarea/entity/WorkArea.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/workarea/entity/WorkArea.java new file mode 100644 index 0000000..0f1ae1a --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/workarea/entity/WorkArea.java @@ -0,0 +1,54 @@ +package com.hnac.hzims.safeproduct.workarea.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@TableName("work_area") +public class WorkArea { + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 区域名称 + */ + @TableField("area_name") + private String areaName; + + /** + * 安全责任人 + */ + @TableField("direct_op_id") + private Long directOpId; + + /** + * 监管部门 + */ + @TableField("depart_id") + private Long departId; + + /** + * 分管领导 + */ + @TableField("lead_op_id") + private Long leadOpId; + + /** + * 区域范围 + */ + @TableField("area_range") + private String areaRange; + + private String directOpName; + + private String departName; + + private String leadOpName; +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/workarea/vo/WorkAreaQueryVo.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/workarea/vo/WorkAreaQueryVo.java new file mode 100644 index 0000000..61c2160 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/workarea/vo/WorkAreaQueryVo.java @@ -0,0 +1,32 @@ +package com.hnac.hzims.safeproduct.workarea.vo; + +import com.baomidou.mybatisplus.annotation.TableField; +import lombok.Data; + +@Data +public class WorkAreaQueryVo { + + /** + * 区域名称 + */ + @TableField("area_name") + private String areaName; + + /** + * 安全责任人 + */ + @TableField("direct_op_id") + private Long directOpId; + + /** + * 监管部门 + */ + @TableField("depart_id") + private Long departId; + + /** + * 分管领导 + */ + @TableField("lead_op_id") + private Long leadOpId; +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/controller/WorkAreaController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/controller/WorkAreaController.java new file mode 100644 index 0000000..b8de9d9 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/controller/WorkAreaController.java @@ -0,0 +1,63 @@ +package com.hnac.hzims.safeproduct.workarea.controller; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.hnac.hzims.safeproduct.workarea.entity.WorkArea; +import com.hnac.hzims.safeproduct.workarea.service.WorkAreaService; +import com.hnac.hzims.safeproduct.workarea.vo.WorkAreaQueryVo; +import lombok.RequiredArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/workarea") +public class WorkAreaController { + + @Autowired + WorkAreaService workAreaService; + + /** + * 分页查询 + */ + @GetMapping("/listPage/{page}/{size}") + public R listPage(@PathVariable Long page, + @PathVariable Long size, + WorkAreaQueryVo workAreaQueryVo) { + Page pageParam = new Page<>(page, size); + IPage resultParams = + workAreaService.selectPage(pageParam, + workAreaQueryVo); + return R.data(resultParams); + } + + /** + * 新增工作区域数据 + */ + @PostMapping("/save") + public R save(@RequestBody WorkArea workArea) { + workAreaService.saveWorkArea(workArea); + return R.success("新增成功"); + } + + + /** + * 更新工作区域数据 + */ + @PutMapping("/update") + public R update(@RequestBody WorkArea workArea) { + workAreaService.updateWorkArea(workArea); + return R.success("修改成功"); + } + + + /** + * 删除工作区域数据 + */ + @DeleteMapping("/remove/{id}") + public R remove(@PathVariable Long id) { + workAreaService.removeById(id); + return R.success("删除成功"); + } +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/mapper/WorkAreaMapper.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/mapper/WorkAreaMapper.java new file mode 100644 index 0000000..f3e3dba --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/mapper/WorkAreaMapper.java @@ -0,0 +1,7 @@ +package com.hnac.hzims.safeproduct.workarea.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hnac.hzims.safeproduct.workarea.entity.WorkArea; + +public interface WorkAreaMapper extends BaseMapper { +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/service/WorkAreaService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/service/WorkAreaService.java new file mode 100644 index 0000000..645db2d --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/service/WorkAreaService.java @@ -0,0 +1,22 @@ +package com.hnac.hzims.safeproduct.workarea.service; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.hzims.safeproduct.workarea.entity.WorkArea; +import com.hnac.hzims.safeproduct.workarea.vo.WorkAreaQueryVo; + +public interface WorkAreaService extends IService { + + /** + * 分页查询 + * @param pageParam + * @param workAreaQueryVo + * @return + */ + IPage selectPage(Page pageParam, WorkAreaQueryVo workAreaQueryVo); + + void saveWorkArea(WorkArea workArea); + + void updateWorkArea(WorkArea workArea); +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/service/impl/WorkAreaServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/service/impl/WorkAreaServiceImpl.java new file mode 100644 index 0000000..52f07e5 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/service/impl/WorkAreaServiceImpl.java @@ -0,0 +1,93 @@ +package com.hnac.hzims.safeproduct.workarea.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.hnac.hzims.safeproduct.workarea.entity.WorkArea; +import com.hnac.hzims.safeproduct.workarea.mapper.WorkAreaMapper; +import com.hnac.hzims.safeproduct.workarea.service.WorkAreaService; +import com.hnac.hzims.safeproduct.workarea.vo.WorkAreaQueryVo; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.system.cache.SysCache; +import org.springblade.system.entity.Dept; +import org.springblade.system.user.cache.UserCache; +import org.springblade.system.user.entity.User; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class WorkAreaServiceImpl extends ServiceImpl implements WorkAreaService { + + @Override + public IPage selectPage(Page pageParam, WorkAreaQueryVo workAreaQueryVo) { + String areaName = workAreaQueryVo.getAreaName(); + Long directOpId = workAreaQueryVo.getDirectOpId(); + Long leadOpId = workAreaQueryVo.getLeadOpId(); + Long departId = workAreaQueryVo.getDepartId(); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + if (StringUtils.isNotBlank(areaName)) { + queryWrapper.like(WorkArea::getAreaName,areaName); + } + if (ObjectUtil.isNotEmpty(directOpId)) { + queryWrapper.eq(WorkArea::getDirectOpId, directOpId); + } + if (ObjectUtil.isNotEmpty(leadOpId)) { + queryWrapper.eq(WorkArea::getLeadOpId, leadOpId); + } + if (ObjectUtil.isNotEmpty(departId)) { + queryWrapper.eq(WorkArea::getDepartId, departId); + } + IPage workAreaIPage = baseMapper.selectPage(pageParam, queryWrapper); + + //翻译 + List records = workAreaIPage.getRecords(); + records.stream().forEach(workArea -> { + User directOp = UserCache.getUser(workArea.getDirectOpId()); + String directOpName = directOp.getName(); + User leadOp = UserCache.getUser(workArea.getLeadOpId()); + String leadOpName = leadOp.getName(); + Dept dept = SysCache.getDept(workArea.getDepartId()); + String deptName = dept.getDeptName(); + workArea.setDirectOpName(directOpName); + workArea.setLeadOpName(leadOpName); + workArea.setDepartName(deptName); + }); + + return workAreaIPage; + } + + @Override + public void saveWorkArea(WorkArea workArea) { + checkOpAndDept(workArea); + this.save(workArea); + } + + @Override + public void updateWorkArea(WorkArea workArea) { + checkOpAndDept(workArea); + this.updateById(workArea); + } + + /** + * 校验员工id、部门id是否存在 + * @param workArea + */ + private void checkOpAndDept(WorkArea workArea) { + Long directOpId = workArea.getDirectOpId(); + Long leadOpId = workArea.getLeadOpId(); + Long departId = workArea.getDepartId(); + User user = UserCache.getUser(directOpId); + User user1 = UserCache.getUser(leadOpId); + if (user == null || user1 == null) { + throw new ServiceException("员工不存在,保存失败"); + } + Dept dept = SysCache.getDept(departId); + if (dept == null) { + throw new ServiceException("部门不存在,保存失败"); + } + } +}