Browse Source

@作业区域管理@翟千民

zhongwei
zhaiqm 1 year ago
parent
commit
5998b4a846
  1. 54
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/workarea/entity/WorkArea.java
  2. 32
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/workarea/vo/WorkAreaQueryVo.java
  3. 63
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/controller/WorkAreaController.java
  4. 7
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/mapper/WorkAreaMapper.java
  5. 22
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/service/WorkAreaService.java
  6. 93
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/workarea/service/impl/WorkAreaServiceImpl.java

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

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

63
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<WorkArea> pageParam = new Page<>(page, size);
IPage<WorkArea> 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("删除成功");
}
}

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

22
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<WorkArea> {
/**
* 分页查询
* @param pageParam
* @param workAreaQueryVo
* @return
*/
IPage<WorkArea> selectPage(Page<WorkArea> pageParam, WorkAreaQueryVo workAreaQueryVo);
void saveWorkArea(WorkArea workArea);
void updateWorkArea(WorkArea workArea);
}

93
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<WorkAreaMapper, WorkArea> implements WorkAreaService {
@Override
public IPage<WorkArea> selectPage(Page<WorkArea> pageParam, WorkAreaQueryVo workAreaQueryVo) {
String areaName = workAreaQueryVo.getAreaName();
Long directOpId = workAreaQueryVo.getDirectOpId();
Long leadOpId = workAreaQueryVo.getLeadOpId();
Long departId = workAreaQueryVo.getDepartId();
LambdaQueryWrapper<WorkArea> 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<WorkArea> workAreaIPage = baseMapper.selectPage(pageParam, queryWrapper);
//翻译
List<WorkArea> 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("部门不存在,保存失败");
}
}
}
Loading…
Cancel
Save