273 lines
11 KiB
Java
273 lines
11 KiB
Java
package com.zcloud.service.firemanager.impl;
|
||
|
||
import java.util.*;
|
||
|
||
import javax.annotation.Resource;
|
||
|
||
import com.alibaba.fastjson.JSONObject;
|
||
import com.zcloud.mapper.datasource.firemanager.FireChangeLogMapper;
|
||
import com.zcloud.util.*;
|
||
import org.springframework.stereotype.Service;
|
||
import org.springframework.transaction.annotation.Transactional;
|
||
|
||
import com.zcloud.entity.Page;
|
||
import com.zcloud.entity.PageData;
|
||
import com.zcloud.entity.system.Dictionaries;
|
||
import com.zcloud.mapper.datasource.firemanager.FireDeviceMapper;
|
||
import com.zcloud.service.firemanager.FireDeviceService;
|
||
import com.zcloud.service.firemanager.FirePointService;
|
||
import com.zcloud.service.firemanager.FireRegionService;
|
||
import com.zcloud.service.system.DepartmentService;
|
||
import com.zcloud.service.system.DictionariesService;
|
||
import com.zcloud.service.system.UsersService;
|
||
|
||
/**
|
||
* 说明:消防器材 作者:wangxuan 官网:www.zcloudchina.com
|
||
*/
|
||
@Service
|
||
public class FireDeviceServiceImpl implements FireDeviceService {
|
||
|
||
@Resource
|
||
private FireDeviceMapper fireDeviceMapper;
|
||
@Resource
|
||
private FireChangeLogMapper fireChangeLogMapper;
|
||
@Resource
|
||
private FireRegionService fireRegionService;
|
||
@Resource
|
||
private FirePointService firePointService;
|
||
@Resource
|
||
private DictionariesService dictionariesService;
|
||
@Resource
|
||
private UsersService usersService;
|
||
|
||
@Resource
|
||
private InitPageDataUtil initPageDataUtil;
|
||
|
||
@Resource
|
||
private DepartmentService departmentService;
|
||
|
||
@Override
|
||
public List<PageData> list(Page page) {
|
||
return fireDeviceMapper.datalistPage(page);
|
||
}
|
||
|
||
@Override
|
||
public PageData findById(PageData pd) {
|
||
return fireDeviceMapper.findById(pd);
|
||
}
|
||
|
||
@Override
|
||
@Transactional
|
||
public void updFireDeviceById(PageData pd) {
|
||
fireDeviceMapper.updFireDeviceById(pd);
|
||
}
|
||
|
||
@Override
|
||
@Transactional(rollbackFor = Exception.class)
|
||
public boolean delFireDeviceByIds(PageData pd) {
|
||
PageData pageData = fireDeviceMapper.tryDel(pd);
|
||
if ("0".equals(String.valueOf(pageData.get("sum")))) {
|
||
fireDeviceMapper.delFireDeviceByIds(pd);
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
@Override
|
||
@Transactional
|
||
public void saveDeviceInfo(PageData pd) {
|
||
fireDeviceMapper.saveDeviceInfo(pd);
|
||
}
|
||
|
||
@Override
|
||
public List<PageData> getDeviceListByPointId(PageData pageData) {
|
||
return fireDeviceMapper.getDeviceListByPointId(pageData);
|
||
}
|
||
|
||
@Override
|
||
public PageData getPointCode(PageData pageData) {
|
||
return fireDeviceMapper.getPointCode(pageData);
|
||
}
|
||
|
||
@Override
|
||
@Transactional(rollbackFor = Exception.class)
|
||
public void doRemoveDeviceHidden(String hiddenId) {
|
||
fireDeviceMapper.doRemoveDeviceHidden(hiddenId);
|
||
}
|
||
|
||
@Override
|
||
@Transactional(rollbackFor = Exception.class)
|
||
public void addHidden4Device(LinkedList<PageData> addHiddenDeviceList) {
|
||
// 对设备添加隐患
|
||
addHiddenDeviceList.forEach(item -> {
|
||
fireDeviceMapper.addHidden4Device(item);
|
||
});
|
||
}
|
||
|
||
@Override
|
||
public List<PageData> getStandardIDByDeviceID(PageData queryData) {
|
||
return fireDeviceMapper.getStandardIDByDeviceID(queryData);
|
||
}
|
||
|
||
@Override
|
||
public Map<String, Integer> getcodeByCorp(PageData pd) throws Exception {
|
||
Map<String, Integer> map = new HashMap<>();
|
||
List<PageData> list = fireDeviceMapper.listAll(pd);
|
||
for (PageData pageData : list) {
|
||
map.put(pageData.getString("FIRE_DEVICE_CODE"), 0);
|
||
}
|
||
return map;
|
||
}
|
||
|
||
@Override
|
||
public Map<String, Object> saveToExcel(List<PageData> listPd) throws Exception {
|
||
|
||
PageData pd = new PageData();
|
||
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
|
||
Map<String, PageData> getquyeListAll = fireRegionService.getAllByCorpIdForExcel(pd); // 获取数据库中的所有消防区域
|
||
Map<String, PageData> getdianweiListAll = firePointService.getAllByCorpIdForExcel(pd); // 获取数据库中的所有消防点位
|
||
|
||
Map<String, Dictionaries> getDicMap = dictionariesService.getMapByParId("249151f04fd64132a949fdd430a7b9c5");
|
||
|
||
Map<String, String> getCorpDepartAllMap = departmentService.getDepartMapFroExcel(pd); // 这个企业的所有部门
|
||
Map<String, String> getCorpUserAllMap = usersService.getUserMapFroExcel(pd); // 这个企业的所有人员
|
||
|
||
for (PageData lpd : listPd) { // 判断必填 等信息 ,如果这里的信息通过,就要 新增信息
|
||
String xfqyName = Tools.isEmpty(lpd.get("var1")) ? "" : Tools.excelHandle(lpd.get("var1"));
|
||
String xfqyBianma = Tools.isEmpty(lpd.get("var2")) ? "" : Tools.excelHandle(lpd.get("var2"));
|
||
String dwName = Tools.isEmpty(lpd.get("var3")) ? "" : Tools.excelHandle(lpd.get("var3"));
|
||
String dwBianma = Tools.isEmpty(lpd.get("var4")) ? "" : Tools.excelHandle(lpd.get("var4"));
|
||
String departName = Tools.isEmpty(lpd.get("var5")) ? "" : Tools.excelHandle(lpd.get("var5"));
|
||
String userName = Tools.isEmpty(lpd.get("var6")) ? "" : Tools.excelHandle(lpd.get("var6"));
|
||
String xfLxName = Tools.isEmpty(lpd.get("var7")) ? "" : Tools.excelHandle(lpd.get("var7"));
|
||
String code = Tools.isEmpty(lpd.get("var8")) ? "" : Tools.excelHandle(lpd.get("var8"));
|
||
String startTime = Tools.isEmpty(lpd.get("var9")) ? "" : Tools.excelHandle(lpd.get("var9"));
|
||
String endTime = Tools.isEmpty(lpd.get("var10")) ? "" : Tools.excelHandle(lpd.get("var10"));
|
||
String REMAKE = Tools.isEmpty(lpd.get("var11")) ? "" : Tools.excelHandle(lpd.get("var11"));
|
||
|
||
String departId = "";
|
||
if (getCorpDepartAllMap.containsKey(departName)) {
|
||
departId = getCorpDepartAllMap.get(departName);
|
||
}
|
||
String userID = "";
|
||
if (getCorpUserAllMap.containsKey(userName)) {
|
||
userID = getCorpUserAllMap.get(userName);
|
||
}
|
||
|
||
PageData qyPd = new PageData();
|
||
PageData dwPd = new PageData();
|
||
Dictionaries xfLcDic = new Dictionaries();
|
||
if (!getquyeListAll.containsKey(xfqyName + "--" + xfqyBianma)) {
|
||
// 没有的消防区域,增加消防区域
|
||
qyPd = fireRegionService.savaByExcel(xfqyName, xfqyBianma, departId); // 新增这个区域
|
||
getquyeListAll.put(xfqyName + "--" + xfqyBianma, qyPd);
|
||
} else {
|
||
qyPd = getquyeListAll.get(xfqyName + "--" + xfqyBianma);
|
||
}
|
||
if (!getdianweiListAll.containsKey(dwName + "--" + dwBianma + "--" + qyPd.getString("FIRE_REGION_ID"))) { // 这个消防区域没有这个点位
|
||
dwPd = firePointService.saveFroExcel(dwName, dwBianma, qyPd.getString("FIRE_REGION_ID"), departId, userID); // 新增点位
|
||
getdianweiListAll.put(dwName + "--" + dwBianma + "--" + qyPd.getString("FIRE_REGION_ID"), dwPd);
|
||
} else {
|
||
dwPd = getdianweiListAll.get(dwName + "--" + dwBianma + "--" + qyPd.getString("FIRE_REGION_ID"));
|
||
}
|
||
if (getDicMap.containsKey(xfLxName)) {
|
||
xfLcDic = getDicMap.get(xfLxName);
|
||
}
|
||
PageData qc = this.saveFroExcel(qyPd, dwPd, xfLcDic, code, startTime, endTime, REMAKE);
|
||
}
|
||
return null;
|
||
}
|
||
|
||
public PageData saveFroExcel(PageData qyPd, PageData dwPd, Dictionaries xfLcDic, String code, String startTime,
|
||
String endTime, String REMAKE) {
|
||
PageData pd = new PageData();
|
||
pd.put("FIRE_DEVICE_ID", UuidUtil.get32UUID());
|
||
pd.put("CREATOR", Jurisdiction.getUSER_ID());
|
||
pd.put("OPERATOR", Jurisdiction.getUSER_ID());
|
||
pd.put("CREATTIME", DateUtil.date2Str(new Date()));
|
||
pd.put("OPERATTIME", DateUtil.date2Str(new Date()));
|
||
pd.put("ISDELETE", DateUtil.date2Str(new Date()));
|
||
|
||
pd.put("FIRE_DEVICE_CODE", code);
|
||
pd.put("FIRE_REGION_ID", qyPd.getString("FIRE_REGION_ID"));
|
||
pd.put("FIRE_POINT_ID", dwPd.getString("FIRE_POINT_ID"));
|
||
pd.put("FIRE_DEVICE_TYPE_ID", xfLcDic.getBIANMA());
|
||
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
|
||
if (!Tools.isEmpty(startTime)) {
|
||
pd.put("VALIDITY_START_TIME", DateUtil.date2Str(DateUtil.getDateByDayInt(Integer.parseInt(startTime))));
|
||
}
|
||
if (!Tools.isEmpty(endTime)) {
|
||
pd.put("VALIDITY_END_TIME", DateUtil.date2Str(DateUtil.getDateByDayInt(Integer.parseInt(endTime))));
|
||
}
|
||
pd.put("REMAKE", REMAKE);
|
||
pd.put("DEPARTMENT_ID", qyPd.getString("DEPARTMENT_ID"));
|
||
this.saveDeviceInfo(pd);
|
||
return pd;
|
||
}
|
||
|
||
@Override
|
||
public PageData getDeviceById(PageData pd) throws Exception {
|
||
return fireDeviceMapper.getDeviceById(pd);
|
||
}
|
||
|
||
@Override
|
||
public PageData hasFireDeviceCode(PageData pd) throws Exception {
|
||
// 有设备id 查一下当前的编号与本设备是否相同
|
||
if (Tools.notEmpty(pd.getString("FIRE_DEVICE_ID"))) {
|
||
PageData deviceById = fireDeviceMapper.getDeviceById(pd);
|
||
if (deviceById.getString("FIRE_DEVICE_CODE").equals(pd.getString("FIRE_DEVICE_CODE"))) {
|
||
PageData pageData = new PageData();
|
||
pageData.put("DEVICE_CODE_NUM", "0");
|
||
return pageData;
|
||
}
|
||
}
|
||
// FIRE_DEVICE_CODE
|
||
PageData list = fireDeviceMapper.getDeviceCodeNum(pd);
|
||
return list;
|
||
}
|
||
|
||
@Override
|
||
@Transactional(rollbackFor = Exception.class)
|
||
public void updPointDepAuserByRegId(PageData pageData) {
|
||
fireDeviceMapper.updPointDepAuserByRegId(pageData);
|
||
}
|
||
|
||
@Override
|
||
@Transactional(rollbackFor = Exception.class)
|
||
public void removeFireDeviceByIds(PageData pd) {
|
||
// 删除设备 但是设备会在其他点检表里用,如果在表里用也删除掉,但是留下记录。
|
||
String DATA_IDS = pd.getString("DATA_IDS");
|
||
if (Tools.notEmpty(DATA_IDS)) {
|
||
String ArrayDATA_IDS[] = DATA_IDS.split(",");
|
||
pd.put("ArrayDATA_IDS", ArrayDATA_IDS);
|
||
List<PageData> fireCheckIdList = fireDeviceMapper.getFireCheckIdByDeciveID(pd);
|
||
StringBuilder stringBuilder = new StringBuilder();
|
||
for (PageData pageData : fireCheckIdList) {
|
||
pageData.put("CARRYINGDATA", JSONObject.toJSONString(pd));
|
||
pageData.put("FIRE_CHANGE_LOG",UuidUtil.get32UUID());
|
||
pageData.put("OPERATE",2);
|
||
pageData.put("OPERATOR",Jurisdiction.getUSER_ID());
|
||
pageData.put("OPERATTIME",DateUtil.date2Str(new Date()));
|
||
pageData.put("OPERATOR_NAME",Jurisdiction.getName());
|
||
stringBuilder.append("删除了编号为:").append(pageData.getString("FIRE_DEVICE_CODE"))
|
||
.append("。类型为:").append(pageData.getString("FIRE_DEVICE_TYPE_NAME")).append("的消防器材");
|
||
pageData.put("SKETCH",stringBuilder.toString());
|
||
stringBuilder.setLength(0);
|
||
}
|
||
if (fireCheckIdList.size() > 0) {
|
||
fireChangeLogMapper.saveBatch(fireCheckIdList);
|
||
fireDeviceMapper.delDevicePreparedByIds(fireCheckIdList);
|
||
}
|
||
initPageDataUtil.initEdit(pd);
|
||
fireDeviceMapper.deleteAll(pd);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public List<PageData> exportDataList(PageData pd) throws Exception {
|
||
return fireDeviceMapper.exportDataList(pd);
|
||
}
|
||
|
||
|
||
}
|