package cn.gistack.sm.sjztmd.service.impl;
|
|
import cn.gistack.sm.sjztmd.entity.TbAttResSafetyMonitor;
|
import cn.gistack.sm.sjztmd.mapper.TbAttResSafetyMonitorMapper;
|
import cn.gistack.sm.sjztmd.service.ITbAttResBaseService;
|
import cn.gistack.sm.sjztmd.service.ITbAttResSafetyMonitorService;
|
import cn.gistack.system.user.feign.IUserClient;
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.springblade.core.secure.utils.AuthUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
|
/**
|
* @ClassName TbAttResSafetyMonitorServiceImpl
|
* @Description TODO
|
* @author zhongrj
|
* @date 2023/8/14
|
* @Version 1.0
|
*/
|
@Service
|
@DS("zt")
|
public class TbAttResSafetyMonitorServiceImpl extends ServiceImpl<TbAttResSafetyMonitorMapper, TbAttResSafetyMonitor> implements ITbAttResSafetyMonitorService {
|
|
@Autowired
|
private IUserClient userClient;
|
|
@Autowired
|
private ITbAttResBaseService tbAttResBaseService;
|
|
/**
|
* 查询水库填报详情信息
|
* @param guid
|
* @return
|
*/
|
@Override
|
public TbAttResSafetyMonitor getDetailByGuid(String guid) {
|
return baseMapper.getDetailByResGuid(guid);
|
}
|
|
/**
|
* 编辑
|
* @param tbAttResSafetyMonitor
|
* @return
|
*/
|
@Override
|
public boolean updateByGuid(TbAttResSafetyMonitor tbAttResSafetyMonitor) {
|
boolean edit = false;
|
// 编辑标记
|
if (tbAttResSafetyMonitor.getCheckState()==4){
|
edit = true;
|
}
|
// 查询是否存在
|
TbAttResSafetyMonitor detail = baseMapper.getDetailByResGuid(tbAttResSafetyMonitor.getResGuid());
|
// 更新日志
|
setUpdateLog(detail,tbAttResSafetyMonitor);
|
// 修改
|
int i = addOrUpdateByGuid(detail,tbAttResSafetyMonitor);
|
if (i>0){
|
// if (!edit) {
|
// tbAttResBaseService.updateFinalState(tbAttResSafetyMonitor.getResGuid(), 0);
|
// }
|
return true;
|
}
|
return false;
|
}
|
|
/**
|
* 审核
|
* @param tbAttResSafetyMonitor
|
* @return
|
*/
|
@Override
|
public boolean auditByGuid(TbAttResSafetyMonitor tbAttResSafetyMonitor) {
|
boolean edit = false;
|
// 编辑标记
|
if (tbAttResSafetyMonitor.getCheckState()==4){
|
edit = true;
|
}
|
// 查询是否存在
|
TbAttResSafetyMonitor detail = baseMapper.getDetailByResGuid(tbAttResSafetyMonitor.getResGuid());
|
// 更新操作日志
|
setUpdateLog(detail,tbAttResSafetyMonitor);
|
// 更新审核日志
|
setUpdateCheckLog(detail,tbAttResSafetyMonitor);
|
if (null!=detail){
|
tbAttResSafetyMonitor.setGuid(detail.getGuid());
|
}
|
// 驳回情况下将状态修改回0即已填写未提交状态
|
if (tbAttResSafetyMonitor.getCheckState()==3){
|
tbAttResSafetyMonitor.setCheckState(0);
|
}
|
|
detail.setCheckState(tbAttResSafetyMonitor.getCheckState());
|
// 更新数据
|
int i = baseMapper.updateById(detail);
|
if (i>0){
|
if (!edit) {
|
tbAttResBaseService.updateFinalState(tbAttResSafetyMonitor.getResGuid(), tbAttResSafetyMonitor.getCheckState());
|
}
|
return true;
|
}
|
return false;
|
}
|
|
/**
|
* 更新
|
* @param tbAttResSafetyMonitor
|
* @return
|
*/
|
private int addOrUpdateByGuid(TbAttResSafetyMonitor oldAbAttResBase,TbAttResSafetyMonitor tbAttResSafetyMonitor){
|
int i = 0;
|
if (null!=oldAbAttResBase){
|
tbAttResSafetyMonitor.setGuid(oldAbAttResBase.getGuid());
|
// 更新
|
i = baseMapper.updateById(tbAttResSafetyMonitor);
|
tbAttResBaseService.updateFinalState(tbAttResSafetyMonitor.getResGuid(),tbAttResSafetyMonitor.getCheckState());
|
}else {
|
tbAttResSafetyMonitor.setCreateTime(new Date());
|
i = baseMapper.insert(tbAttResSafetyMonitor);
|
}
|
// 返回
|
return i;
|
}
|
|
/**
|
* @param oldAbAttResBase
|
* @param newTbAttResSafetyMonitor
|
* 更新审核记录
|
*/
|
private void setUpdateCheckLog(TbAttResSafetyMonitor oldAbAttResBase,TbAttResSafetyMonitor newTbAttResSafetyMonitor) {
|
String fillName = "";
|
if (newTbAttResSafetyMonitor.getCheckState()==2){
|
fillName = "审核";
|
}
|
if (newTbAttResSafetyMonitor.getCheckState()==3){
|
fillName = "退回" + (null==newTbAttResSafetyMonitor.getCheckLog()?"":":" + newTbAttResSafetyMonitor.getCheckLog());
|
}
|
|
// 拼接
|
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date());
|
String userName = AuthUtil.getUser().getUserName();
|
String phone = userClient.userInfoById(AuthUtil.getUserId()).getData().getPhone();
|
StringBuilder builder = new StringBuilder();
|
builder.append(time)
|
.append(",")
|
.append(fillName)
|
.append(",")
|
.append(userName)
|
.append(",")
|
.append(phone)
|
.append(";");
|
// 判断是否存在
|
if (null==oldAbAttResBase){
|
// 填报
|
newTbAttResSafetyMonitor.setCheckLog(builder.toString());
|
}else {
|
StringBuilder stringBuilder = new StringBuilder(null==oldAbAttResBase.getCheckLog()?"":oldAbAttResBase.getCheckLog());
|
stringBuilder.append(builder);
|
// 填报
|
newTbAttResSafetyMonitor.setCheckLog(stringBuilder.toString());
|
}
|
}
|
|
/**
|
* @param oldAbAttResBase
|
* @param newTbAttResSafetyMonitor
|
* 更新操作记录
|
*/
|
private void setUpdateLog(TbAttResSafetyMonitor oldAbAttResBase,TbAttResSafetyMonitor newTbAttResSafetyMonitor) {
|
String fillName = "";
|
if (newTbAttResSafetyMonitor.getCheckState()==0){
|
fillName = "编辑";
|
}
|
if (newTbAttResSafetyMonitor.getCheckState()==1){
|
fillName = "提交";
|
}
|
if (newTbAttResSafetyMonitor.getCheckState()==2){
|
fillName = "审核";
|
}
|
if (newTbAttResSafetyMonitor.getCheckState()==3){
|
fillName = "退回" + (null==newTbAttResSafetyMonitor.getCheckLog()?"":":" + newTbAttResSafetyMonitor.getCheckLog());
|
}
|
if (newTbAttResSafetyMonitor.getCheckState()==4){
|
fillName = "编辑";
|
newTbAttResSafetyMonitor.setCheckState(oldAbAttResBase.getCheckState());
|
}
|
|
// 拼接
|
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date());
|
String userName = AuthUtil.getUser().getUserName();
|
String phone = userClient.userInfoById(AuthUtil.getUserId()).getData().getPhone();
|
StringBuilder builder = new StringBuilder();
|
builder.append(time)
|
.append(",")
|
.append(fillName)
|
.append(",")
|
.append(userName)
|
.append(",")
|
.append(phone)
|
.append(";");
|
// 判断是否存在
|
if (null==oldAbAttResBase){
|
// 填报
|
newTbAttResSafetyMonitor.setLog(builder.toString());
|
}else {
|
StringBuilder stringBuilder = new StringBuilder(null==oldAbAttResBase.getLog()?"":oldAbAttResBase.getLog());
|
stringBuilder.append(builder);
|
// 填报
|
newTbAttResSafetyMonitor.setLog(stringBuilder.toString());
|
}
|
}
|
}
|