package com.whyc.service;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.whyc.constant.RoleEnum;
|
import com.whyc.constant.WorkflowEnum;
|
import com.whyc.dto.Response;
|
import com.whyc.mapper.Fbs9100SetParamTempMapper;
|
import com.whyc.pojo.Fbs9100SetParamTemp;
|
import com.whyc.pojo.UserInf;
|
import com.whyc.pojo.WorkflowLink;
|
import com.whyc.pojo.WorkflowMain;
|
import com.whyc.util.ActionUtil;
|
import com.whyc.util.ThreadLocalUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.Date;
|
|
@Service
|
public class Fbs9100SetParamTempService {
|
@Autowired(required = false)
|
private Fbs9100SetParamTempMapper mapper;
|
|
@Autowired(required = false)
|
private WorkflowMainService mainService;
|
|
@Autowired(required = false)
|
private WorkflowLinkService linkService;
|
|
//该设备放电申请
|
public Response searchTemp(int battGroupId) {
|
Fbs9100SetParamTemp temp = mapper.searchTemp(battGroupId);
|
return new Response().setII(1, temp == null ? false : true, temp, "设备放电申请");
|
}
|
|
//二次放电发起申请
|
@Transactional
|
public Response addTmpWorkMain(Fbs9100SetParamTemp tmp, UserInf uinf) {
|
//判断用户角色,管理员和领导层不能申请
|
if (uinf.getURole() == 0 || uinf.getURole() == 10) {
|
return new Response().set(1, false, "管理专责和领导层不能发起申请");
|
}
|
//1.提交到单据审批流程
|
//查询表单编号
|
int id = mainService.getMaxId();
|
WorkflowMain main = new WorkflowMain();
|
String orderId = mainService.getNextOrderId("ECHR");
|
//String title = "二次放电审批单-" + ActionUtil.sdf.format(new Date());
|
String title = "二次放电审批单-" + ThreadLocalUtil.format(new Date(),1);
|
Integer mainStatus = WorkflowEnum.MAIN_STATUS_DEALING.getValue();
|
Integer mainType = WorkflowEnum.MAIN_TYPE_DISCHARGE_DIST.getValue();
|
main.setOrderId(orderId);
|
main.setTitle(title);
|
main.setTaskDesc(tmp.getReason());
|
main.setCreateUserId(Integer.parseInt(uinf.getUId().toString()));
|
main.setCreateTime(new Date());
|
main.setBeginTime(new Date());
|
main.setStatus(mainStatus);
|
main.setType(mainType);
|
main.setId(id);
|
main.setProcessLevel("P2");
|
mainService.addWorkMain(main);
|
//link添加
|
WorkflowLink link = new WorkflowLink();
|
link.setMainId(id);
|
link.setParentId(0);
|
link.setDealDesc("管理员处理中");
|
link.setProcessLevelName("管理审批");
|
link.setCreateTime(new Date());
|
link.setDealUserId(null);
|
link.setProcessLevel("P2");
|
link.setDealRoleId(RoleEnum.ADMIN.getId());//默认申请给管理层
|
link.setDealType(WorkflowEnum.TYPE_DELIVER.getValue());
|
link.setStatus(WorkflowEnum.STATUS_TAKING.getValue());//默认待处理
|
linkService.add(link);
|
//2.添加二次放电参数
|
tmp.setMainId(id);
|
tmp.setIsCharge(0);
|
insert(tmp);
|
return new Response().set(1, true, "二次放电申请");
|
}
|
|
//添加二次放电参数
|
public void insert(Fbs9100SetParamTemp tmp) {
|
//判断是否存在该设备id的记录
|
QueryWrapper wrapper = Wrappers.query();
|
wrapper.eq("dev_id", tmp.getDevId());
|
wrapper.eq("battGroupId", tmp.getBattGroupId());
|
wrapper.eq("noworhis", 0);
|
wrapper.last("limit 1");
|
Fbs9100SetParamTemp paramTemp = mapper.selectOne(wrapper);
|
if (paramTemp != null) {
|
UpdateWrapper uWrapper = Wrappers.update();
|
uWrapper.eq("dev_id", tmp.getDevId());
|
uWrapper.eq("battGroupId", tmp.getBattGroupId());
|
uWrapper.eq("noworhis", 0);
|
uWrapper.set("noworhis", 1);
|
mapper.update((Fbs9100SetParamTemp) ActionUtil.objeNull, uWrapper);
|
}
|
mapper.insertTmp(tmp);
|
}
|
}
|