package org.jeecg.modules.eam.controller;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.shiro.SecurityUtils;
|
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
import org.jeecg.common.constant.CommonConstant;
|
import org.jeecg.common.system.api.ISysBaseAPI;
|
import org.jeecg.common.system.base.controller.JeecgController;
|
import org.jeecg.common.system.base.entity.DataVersion;
|
import org.jeecg.common.system.query.QueryGenerator;
|
import org.jeecg.common.system.vo.LoginUser;
|
import org.jeecg.common.util.DateUtils;
|
|
import org.jeecg.modules.eam.entity.*;
|
import org.jeecg.modules.eam.mapper.InspectionCycleMapper;
|
import org.jeecg.modules.eam.service.IInspectionCycleService;
|
import org.jeecg.modules.eam.service.IInspectionProjectService;
|
|
import org.jeecg.modules.eam.service.IdentityService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.math.BigDecimal;
|
import java.text.ParseException;
|
import java.time.LocalDateTime;
|
import java.time.format.DateTimeFormatter;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* @Description: mom_eam_inspection_cycle
|
* @Author: cj
|
* @Date: 2023-04-06
|
* @Version: V1.0
|
*/
|
@Api(tags = "点检周期规则")
|
@RestController
|
@RequestMapping("/eam/inspectionCycle")
|
@Slf4j
|
public class InspectionCycleController extends JeecgController<InspectionCycle, IInspectionCycleService> {
|
|
|
@Autowired
|
private IInspectionCycleService inspectionCycleService;
|
|
|
@Autowired
|
private ISysBaseAPI sysBaseApi;
|
|
@Autowired
|
private InspectionCycleMapper inspectionCycleMapper;
|
|
@Autowired
|
@Lazy
|
private IdentityService sysIdentityService;
|
|
|
//
|
//
|
// @Autowired
|
// private IDataVersionService dataVersionService;
|
//
|
// @Autowired
|
// private IEnterpriseService enterpriseService;
|
//
|
// @Autowired
|
// private IQuartzJobService quartzJobService;
|
//
|
// @Autowired
|
// private ISysDictService dictService;
|
|
|
/**
|
* 分页列表查询
|
*
|
* @param inspectionCycle
|
* @param pageNo
|
* @param pageSize
|
* @param req
|
* @return
|
*/
|
@ApiOperation(value = "点检周期规则-分页列表查询", notes = "点检周期规则-分页列表查询")
|
@GetMapping(value = "/list")
|
public Result<IPage<Map<String, Object>>> queryPageList(InspectionCycle inspectionCycle, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
|
Page<Map<String, Object>> page = new Page(pageNo, pageSize);
|
IPage<Map<String, Object>> pageList = inspectionCycleService.page(page, inspectionCycle);
|
return Result.OK(pageList);
|
}
|
|
|
/**
|
* 添加
|
*
|
* @param map
|
* @return
|
*/
|
@ApiOperation(value = "点检周期规则-添加", notes = "点检周期规则-添加")
|
@PostMapping(value = "/add")
|
public Result<String> add(@RequestBody Map<String, Object> map) {
|
InspectionCycle inspectionCycle = new InspectionCycle();
|
// String cycleUnit = dictService.queryDictTextByKey("cycle_unit", String.valueOf(map.get("cycleUnit")));
|
String cycleUnit = sysBaseApi.queryDictTextByKey("cycle_unit", String.valueOf(map.get("cycleUnit")));
|
inspectionCycle.setCode(String.valueOf(map.get("code"))).setName(String.valueOf(map.get("cycle")).concat(cycleUnit)).setCycle(new BigDecimal(String.valueOf(map.get("cycle")))).setCycleUnit(String.valueOf(map.get("cycleUnit"))).setArrangeWay(String.valueOf(map.get("arrangeWay"))).setAuditStatus(String.valueOf(map.get("auditStatus"))).setCalendar(String.valueOf(map.get("calendar"))).setEffectiveTime(new BigDecimal(String.valueOf(map.get("effectiveTime")))).setEnterpriseId(String.valueOf(map.get("enterpriseId"))).setUnit(String.valueOf(map.get("unit"))).setStartCondition(String.valueOf(map.get("startCondition"))).setLeadTime(new BigDecimal(String.valueOf(map.get("leadTime")))).setVersion(String.valueOf(map.get("version"))).setFirstInspectionTime(DateUtils.str2Date(String.valueOf(map.get("firstInspectionTime")), DateUtils.datetimeFormat.get())).setDelFlag(0);
|
inspectionCycleService.save(inspectionCycle);
|
QueryWrapper<InspectionCycle> queryWrapper = new QueryWrapper<InspectionCycle>().eq("code", inspectionCycle.getCode()).eq("version", inspectionCycle.getVersion()).eq("del_flag", 0);
|
InspectionCycle selectInspectionCycle = inspectionCycleService.getOne(queryWrapper, true);
|
DataVersion dataVersion = new DataVersion();
|
dataVersion.setBusinessId(selectInspectionCycle.getId())
|
.setBusinessType("点检周期").setErterpriseId(String.valueOf(map.get("enterpriseId")))
|
.setVersion(Integer.parseInt(selectInspectionCycle.getVersion()))
|
.setVersionStatus(String.valueOf(map.get("versionStatus"))).setDelFlag(0).setEffectiveType("0").setIsLastUsable("0");
|
sysBaseApi.saveDataVersion(dataVersion);
|
/* QueryWrapper<DataVersion> queryWrapper1 = new QueryWrapper<DataVersion>()
|
.eq("business_id",selectInspectionCycle.getId()).eq("del_flag",0);
|
DataVersion selectDataVersion = dataVersionService.getOne(queryWrapper1,true);
|
selectInspectionCycle.setDataVersionId(selectDataVersion.getId());
|
inspectionCycleService.saveOrUpdate(selectInspectionCycle);*/
|
return Result.OK("添加成功!");
|
}
|
|
/**
|
* 添加
|
*/
|
@PostMapping(value = "/addNew")
|
public Result<String> addNew(@RequestBody InspectionCycle inspectionCycle) {
|
String cycleUnit = sysBaseApi.queryDictTextByKey("cycle_unit", String.valueOf(inspectionCycle.getCycleUnit()));
|
inspectionCycle.setName(String.valueOf(inspectionCycle.getCycle()).concat(cycleUnit));
|
// String num = "DJ" + DateUtils.date2Str(DateUtils.yyyyMMdd.get()) + inspectionCycleMapper.getInspectionCycleNum();
|
String num = sysIdentityService.getNumByTypeAndLength("InspectionCycle", 4);
|
inspectionCycle.setCode(num);
|
inspectionCycleService.save(inspectionCycle);
|
return Result.OK("添加成功!");
|
}
|
|
/**
|
* 编辑
|
*
|
* @param inspectionCycle
|
* @return
|
*/
|
@ApiOperation(value = "点检周期规则-编辑", notes = "点检周期规则-编辑")
|
@RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
|
public Result<String> edit(@RequestBody InspectionCycle inspectionCycle) {
|
inspectionCycleService.updateById(inspectionCycle);
|
return Result.OK("编辑成功!");
|
}
|
|
/**
|
* 通过id删除
|
*
|
* @param id
|
* @return
|
*/
|
@ApiOperation(value = "点检周期规则-通过id删除", notes = "点检周期规则-通过id删除")
|
@DeleteMapping(value = "/delete")
|
public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
|
// dataVersionService.update(new UpdateWrapper<DataVersion>().set("del_flag", 1).eq("business_id", id));
|
sysBaseApi.removeDataVersionById(id);
|
// inspectionCycleService.update(new UpdateWrapper<InspectionCycle>().set("del_flag", 1).eq("id", id));
|
inspectionCycleService.removeById(id);
|
return Result.OK("删除成功!");
|
}
|
|
/**
|
* 批量删除
|
*
|
* @param ids
|
* @return
|
*/
|
@ApiOperation(value = "点检周期规则-批量删除", notes = "点检周期规则-批量删除")
|
@DeleteMapping(value = "/deleteBatch")
|
public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
// dataVersionService.update(new UpdateWrapper<DataVersion>().set("del_flag", 1).in("business_id", Arrays.asList(ids.split(","))));
|
// inspectionCycleService.update(new UpdateWrapper<InspectionCycle>().set("del_flag", 1).in("id", Arrays.asList(ids.split(","))));
|
sysBaseApi.removeDataVersionByIds(ids);
|
return Result.OK("批量删除成功!");
|
}
|
|
/**
|
* 获取初始信息
|
*/
|
@GetMapping("/getInspectionCycleInfo")
|
public Result<?> getInspectionCycleInfo() {
|
Map<String, Object> infoMap = new HashMap<>(3);
|
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
// String enterpriseName = enterpriseService.lambdaQuery().eq(Enterprise::getId, loginUser.getEnterpriseId()).eq(Enterprise::getDelFlag, CommonConstant.DEL_FLAG_0).one().getName();
|
String enterpriseName = sysBaseApi.getEnterpriseNameById(loginUser.getEnterpriseId());
|
infoMap.put("enterpriseId", loginUser.getEnterpriseId());
|
infoMap.put("enterpriseName", enterpriseName);
|
if (CollectionUtils.isNotEmpty(inspectionCycleService.getUsableVersion())) {
|
infoMap.put("version", inspectionCycleService.getUsableVersion().get(0));
|
// String versionStatus = dataVersionService.lambdaQuery().eq(DataVersion::getVersion, inspectionCycleService.getUsableVersion().get(0)).eq(DataVersion::getBusinessType, "点检周期")
|
// .eq(DataVersion::getDelFlag, CommonConstant.DEL_FLAG_0).list().get(0).getVersionStatus();
|
String versionStatus = sysBaseApi.getVersionStatusByVersionAndBusinessType(inspectionCycleService.getUsableVersion().get(0), "点检周期");
|
infoMap.put("versionStatus", versionStatus);
|
} else {
|
infoMap.put("version", 1);
|
infoMap.put("versionStatus", "0");
|
}
|
return Result.OK(infoMap);
|
}
|
|
/**
|
* 获取所有版本号
|
*/
|
@GetMapping("/getVersionList")
|
public Result<?> getAllVersion() {
|
return Result.OK(inspectionCycleService.getVersionList());
|
}
|
|
/**
|
* 根据版本号获取版本状态
|
*/
|
@PostMapping("/getVersionStatus")
|
public Result<?> getVersionStatus(@RequestBody Map<String, Object> map) {
|
Integer version = Integer.parseInt((String) map.get("version"));
|
// String versionStatus = dataVersionService.lambdaQuery().eq(DataVersion::getVersion, version).eq(DataVersion::getBusinessType, "点检周期")
|
// .eq(DataVersion::getDelFlag, CommonConstant.DEL_FLAG_0).list().get(0).getVersionStatus();
|
String versionStatus = sysBaseApi.getVersionStatusByVersionAndBusinessType(version, "点检周期");
|
return Result.OK(versionStatus);
|
}
|
|
/**
|
* 升版
|
*
|
* @param map
|
* @return
|
*/
|
@PostMapping("/updateVersion")
|
@Transactional
|
public Result<?> updateVersion(@RequestBody Map<String, Object> map) {
|
Integer version = Integer.parseInt((String) map.get("version"));
|
String enterpriseId = String.valueOf(map.get("enterpriseId"));
|
List<InspectionCycle> inspectionCycleList = inspectionCycleService.lambdaQuery().eq(InspectionCycle::getEnterpriseId, enterpriseId).eq(InspectionCycle::getVersion, version).eq(InspectionCycle::getDelFlag, CommonConstant.DEL_FLAG_0).list();
|
Integer newVersion = inspectionCycleService.getVersionList().stream().findFirst().get() + 1;
|
for (InspectionCycle inspectionCycle : inspectionCycleList) {
|
// DataVersion oldDataVersion = dataVersionService.lambdaQuery().eq(DataVersion::getBusinessId, inspectionCycle.getId())
|
// .eq(DataVersion::getDelFlag, CommonConstant.DEL_FLAG_0).one();
|
DataVersion oldDataVersion = sysBaseApi.getDataVersionByBusinessId(inspectionCycle.getId());
|
inspectionCycle.setId(null);
|
inspectionCycle.setVersion(newVersion.toString());
|
inspectionCycleService.save(inspectionCycle);
|
DataVersion dataVersion = new DataVersion();
|
dataVersion.setBusinessId(inspectionCycle.getId()).setBusinessType("点检周期").setVersion(newVersion).setErterpriseId(enterpriseId).setVersionStatus("1").setDelFlag(0).setEffectiveType("0").setSourceVersionId(oldDataVersion.getId()).setIsLastUsable("0");
|
// dataVersionService.save(dataVersion);
|
sysBaseApi.saveDataVersion(dataVersion);
|
}
|
return Result.OK("升版成功", newVersion);
|
}
|
|
/**
|
* 立即生效
|
*
|
* @param map
|
* @param
|
* @return
|
*/
|
@PostMapping("/updateVersionStatusToUsable")
|
@Transactional
|
public Result<?> updateVersionStatusToUsable(@RequestBody Map<String, Object> map) {
|
//如果有定时生生效,则将定时生效任务关闭
|
// QuartzJob quartzJob = quartzJobService.getOne(new QueryWrapper<QuartzJob>().eq("job_class_name", "org.jeecg.modules.quartz.job.InspectionCycleSetUsableJob"), true);
|
// if (ObjectUtils.isNotNull(quartzJob)) {
|
// quartzJobService.deleteAndStopJob(quartzJob);
|
// }
|
sysBaseApi.closeJobByClassName("org.jeecg.modules.quartz.job.InspectionCycleSetUsableJob");
|
//获取版本号
|
Integer version = Integer.parseInt((String) map.get("version"));
|
String enterpriseId = String.valueOf(map.get("enterpriseId"));
|
//将上次生效的是否上次生效置为否
|
// List<DataVersion> lastDataVersions = dataVersionService.lambdaQuery().eq(DataVersion::getBusinessType, "点检周期").eq(DataVersion::getErterpriseId, enterpriseId).eq(DataVersion::getIsLastUsable, "1").list();
|
List<DataVersion> lastDataVersions = sysBaseApi.getLastDataVersion("点检周期", enterpriseId, "1");
|
for (DataVersion dataVersion : lastDataVersions) {
|
dataVersion.setIsLastUsable("0");
|
}
|
// dataVersionService.updateBatchById(lastDataVersions);
|
sysBaseApi.updateBatchDataVersion(lastDataVersions);
|
//将状态为生效的置为失效
|
// List<DataVersion> dataVersions = dataVersionService.lambdaQuery().eq(DataVersion::getBusinessType, "点检周期").eq(DataVersion::getErterpriseId, enterpriseId).eq(DataVersion::getVersionStatus, "2").list();
|
List<DataVersion> dataVersions = sysBaseApi.getDataVersionList("点检周期",enterpriseId,"2",null);
|
for (DataVersion dataVersion : dataVersions) {
|
dataVersion.setVersionStatus("3");
|
dataVersion.setIsLastUsable("1");
|
dataVersion.setExpiredTime(new Date(System.currentTimeMillis()));
|
}
|
// dataVersionService.updateBatchById(dataVersions);
|
sysBaseApi.updateBatchDataVersion(dataVersions);
|
//获取待生效版本及版本信息并将其置为生效
|
// List<DataVersion> dataVersionList = dataVersionService.lambdaQuery().eq(DataVersion::getBusinessType, "点检周期").eq(DataVersion::getVersion, version).eq(DataVersion::getErterpriseId, enterpriseId).list();
|
List<DataVersion> dataVersionList = sysBaseApi.getDataVersionList("点检周期",enterpriseId,null,version.toString());
|
for (DataVersion dataVersion : dataVersionList) {
|
dataVersion.setVersionStatus("2");
|
dataVersion.setEffectiveType("2");
|
dataVersion.setEffectiveTime(new Date(System.currentTimeMillis()));
|
dataVersion.setIsLastUsable("0");
|
}
|
// dataVersionService.updateBatchById(dataVersionList);
|
sysBaseApi.updateBatchDataVersion(dataVersionList);
|
return Result.OK("生效成功");
|
}
|
//
|
// /**
|
// * 定时生效
|
// *
|
// * @param quartzJob
|
// * @param
|
// * @return
|
// */
|
// @PostMapping("/updateVersionStatusToUsableBySetTime")
|
// @Transactional
|
// public Result<?> updateVersionStatusToUsableBySetTime(@RequestBody QuartzJob quartzJob) throws ParseException {
|
// DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
// DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("ss mm HH dd MM ? yyyy");
|
// String jobClassName = quartzJob.getJobClassName();
|
// String time = quartzJob.getCronExpression();
|
// System.out.println(time);
|
// LocalDateTime localDateTime = LocalDateTime.parse(time, dateTimeFormatter);
|
// String cronStr = dateTimeFormatter1.format(localDateTime);
|
// quartzJob.setCronExpression(cronStr);
|
// QueryWrapper<QuartzJob> queryWrapper = new QueryWrapper();
|
// queryWrapper.eq("JOB_CLASS_NAME", jobClassName);
|
// List<QuartzJob> quartzJobs = quartzJobService.list(queryWrapper);
|
// if (CollectionUtils.isEmpty(quartzJobs)) {
|
// quartzJobService.saveAndScheduleJob(quartzJob);
|
// quartzJobs = quartzJobService.list(queryWrapper);
|
// quartzJob.setId(quartzJobs.get(0).getId());
|
// quartzJobService.resumeJob(quartzJob);
|
// return Result.OK(quartzJob);
|
// } else {
|
// quartzJob.setId(quartzJobs.get(0).getId());
|
// quartzJobService.resumeJob(quartzJob);
|
// return Result.OK(quartzJob);
|
// }
|
// }
|
|
/**
|
* 版本升级
|
* qsw 2023-7-26
|
*/
|
@PostMapping(value = "/revise")
|
public Result<String> revise(@RequestBody InspectionCycle inspectionCycle) {
|
String cycleUnit = sysBaseApi.queryDictTextByKey("cycle_unit", String.valueOf(inspectionCycle.getCycleUnit()));
|
inspectionCycle.setId("");
|
inspectionCycle.setName(String.valueOf(inspectionCycle.getCycle()).concat(cycleUnit));
|
inspectionCycle.setCreateTime(new Date());
|
inspectionCycle.setUpdateBy(null);
|
inspectionCycle.setUpdateTime(null);
|
inspectionCycle.setLoseEfficacyTime(null);
|
inspectionCycle.setTakeEffectTime(null);
|
boolean b = inspectionCycleService.save(inspectionCycle);
|
if(b){
|
return Result.OK("版本升级成功!");
|
}else{
|
return Result.error("版本升级失败!");
|
}
|
|
}
|
|
/**
|
* 升版
|
* qsw 2023-7-26
|
*/
|
@RequestMapping("/getReviseVersion")
|
public Result<?> getReviseVersion(@RequestBody InspectionCycle inspectionCycle) {
|
List<InspectionCycle> inspectionCycles = inspectionCycleService.lambdaQuery()
|
.eq(InspectionCycle::getCode, inspectionCycle.getCode())
|
.orderByDesc(InspectionCycle::getVersion).list();
|
String version = inspectionCycles.get(0).getVersion();
|
BigDecimal versionB = new BigDecimal(version);
|
BigDecimal versionCode = versionB.add(new BigDecimal(1));
|
return Result.ok(versionCode.toString());
|
}
|
|
/**
|
* 版本生效
|
* qsw 2023-7-26
|
*/
|
@RequestMapping(value = "/versionTakeEffect", method = {RequestMethod.PUT,RequestMethod.POST})
|
@Transactional(rollbackFor = { Exception.class })
|
public Result<String> versionTakeEffect(@RequestBody InspectionCycle inspectionCycle) {
|
List<InspectionCycle> list = inspectionCycleService.lambdaQuery().eq(InspectionCycle::getCode, inspectionCycle.getCode()).eq(InspectionCycle::getVersionStatus, "2").list();
|
for (InspectionCycle cycle : list) {
|
cycle.setVersionStatus("3");
|
cycle.setLoseEfficacyTime(new Date());
|
inspectionCycleService.updateById(cycle);
|
}
|
inspectionCycle.setTakeEffectTime(new Date());
|
boolean b = inspectionCycleService.updateById(inspectionCycle);
|
if (b){
|
return Result.OK("编辑成功!");
|
}else{
|
return Result.error("编辑失败!");
|
}
|
}
|
}
|