提交 6d10708e authored 作者: ljj234's avatar ljj234

refactor: 修改核查模块(重构)

上级 8cf13554
package com.tykj.dev.union; //package com.tykj.dev.union;
//
import com.tykj.dev.device.allot.repository.AllotBackBillDao; //import com.tykj.dev.device.allot.repository.AllotBackBillDao;
import com.tykj.dev.device.allot.repository.AllotBillDao; //import com.tykj.dev.device.allot.repository.AllotBillDao;
import com.tykj.dev.device.allot.subject.domin.AllotBackBill; //import com.tykj.dev.device.allot.subject.domin.AllotBackBill;
import com.tykj.dev.device.allot.subject.domin.AllotBill; //import com.tykj.dev.device.allot.subject.domin.AllotBill;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckDetail; //import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckDetail;
import com.tykj.dev.device.confirmcheck.repository.DeviceCheckDetailDao; //import com.tykj.dev.device.confirmcheck.repository.DeviceCheckDetailDao;
import com.tykj.dev.device.matching.repository.MatchingDeviceLibraryDao; //import com.tykj.dev.device.matching.repository.MatchingDeviceLibraryDao;
import com.tykj.dev.device.matching.subject.domin.MatchingDeviceLibrary; //import com.tykj.dev.device.matching.subject.domin.MatchingDeviceLibrary;
import com.tykj.dev.device.repair.repository.RepairBackBillDao; //import com.tykj.dev.device.repair.repository.RepairBackBillDao;
import com.tykj.dev.device.repair.repository.RepairBillDao; //import com.tykj.dev.device.repair.repository.RepairBillDao;
import com.tykj.dev.device.repair.repository.RepairDetailDao; //import com.tykj.dev.device.repair.repository.RepairDetailDao;
import com.tykj.dev.device.repair.repository.RepairSendBillDao; //import com.tykj.dev.device.repair.repository.RepairSendBillDao;
import com.tykj.dev.device.repair.subject.domin.RepairBackBill; //import com.tykj.dev.device.repair.subject.domin.RepairBackBill;
import com.tykj.dev.device.repair.subject.domin.RepairBill; //import com.tykj.dev.device.repair.subject.domin.RepairBill;
import com.tykj.dev.device.repair.subject.domin.RepairDetail; //import com.tykj.dev.device.repair.subject.domin.RepairDetail;
import com.tykj.dev.device.repair.subject.domin.RepairSendBill; //import com.tykj.dev.device.repair.subject.domin.RepairSendBill;
import com.tykj.dev.device.selfcheck.repository.SelfCheckBillDao; //import com.tykj.dev.device.selfcheck.repository.SelfCheckBillDao;
import com.tykj.dev.device.selfcheck.subject.domin.SelfCheckBill; //import com.tykj.dev.device.selfcheck.subject.domin.SelfCheckBill;
import com.tykj.dev.device.user.subject.dao.UnitsDao; //import com.tykj.dev.device.user.subject.dao.UnitsDao;
import com.tykj.dev.device.user.subject.entity.Units; //import com.tykj.dev.device.user.subject.entity.Units;
import com.tykj.dev.device.user.util.AuthenticationUtils; //import com.tykj.dev.device.user.util.AuthenticationUtils;
import com.tykj.dev.device.user.util.UserUtils; //import com.tykj.dev.device.user.util.UserUtils;
import com.tykj.dev.device.usereport.repository.DeviceUseReportDao; //import com.tykj.dev.device.usereport.repository.DeviceUseReportDao;
import com.tykj.dev.device.usereport.subject.domin.DeviceUseReport; //import com.tykj.dev.device.usereport.subject.domin.DeviceUseReport;
import com.tykj.dev.misc.utils.SpringUtils; //import com.tykj.dev.misc.utils.SpringUtils;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner; //import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean; //import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.DependsOn; //import org.springframework.context.annotation.DependsOn;
import org.springframework.core.annotation.Order; //import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; //import org.springframework.transaction.annotation.Transactional;
//
import javax.annotation.PostConstruct; //import javax.annotation.PostConstruct;
import javax.annotation.Resource; //import javax.annotation.Resource;
import java.util.Collections; //import java.util.Collections;
import java.util.List; //import java.util.List;
//
@Slf4j //@Slf4j
@Component //@Component
public class DataInit { //public class DataInit {
//
@Resource // @Resource
private UnitsDao unitsDao; // private UnitsDao unitsDao;
//
@Autowired // @Autowired
private AllotBillDao allotBillDao; // private AllotBillDao allotBillDao;
@Autowired // @Autowired
private AllotBackBillDao allotBackBillDao; // private AllotBackBillDao allotBackBillDao;
@Autowired // @Autowired
private RepairBackBillDao repairBackBillDao; // private RepairBackBillDao repairBackBillDao;
@Autowired // @Autowired
private RepairDetailDao repairDetailDao; // private RepairDetailDao repairDetailDao;
@Autowired // @Autowired
private RepairSendBillDao repairSendBillDao; // private RepairSendBillDao repairSendBillDao;
@Autowired // @Autowired
private RepairBillDao repairBillDao; // private RepairBillDao repairBillDao;
@Autowired // @Autowired
private SelfCheckBillDao selfCheckBillDao; // private SelfCheckBillDao selfCheckBillDao;
@Autowired // @Autowired
private DeviceUseReportDao deviceUseReportDao; // private DeviceUseReportDao deviceUseReportDao;
//
@Autowired // @Autowired
private MatchingDeviceLibraryDao matchingDeviceLibraryDao; // private MatchingDeviceLibraryDao matchingDeviceLibraryDao;
//
@Autowired // @Autowired
private UserUtils userUtils; // private UserUtils userUtils;
//
@Autowired // @Autowired
private SpringUtils springUtils; // private SpringUtils springUtils;
//
@Autowired // @Autowired
private com.tykj.dev.device.user.util.AuthenticationUtils AuthenticationUtils; // private com.tykj.dev.device.user.util.AuthenticationUtils AuthenticationUtils;
//
private void initCheckDetailUnitName() { // private void initCheckDetailUnitName() {
// 对现有的数据补充unitId信息 // // 对现有的数据补充unitId信息
allotBillDao.findAll().forEach(this::saveModifyDetail1); // allotBillDao.findAll().forEach(this::saveModifyDetail1);
allotBackBillDao.findAll().forEach(this::saveModifyDetail2); // allotBackBillDao.findAll().forEach(this::saveModifyDetail2);
selfCheckBillDao.findAll().forEach(this::saveModifyDetail3); // selfCheckBillDao.findAll().forEach(this::saveModifyDetail3);
repairBillDao.findAll().forEach(this::saveModifyDetail4); // repairBillDao.findAll().forEach(this::saveModifyDetail4);
repairSendBillDao.findAll().forEach(this::saveModifyDetail5); // repairSendBillDao.findAll().forEach(this::saveModifyDetail5);
repairDetailDao.findAll().forEach(this::saveModifyDetail6); // repairDetailDao.findAll().forEach(this::saveModifyDetail6);
repairBackBillDao.findAll().forEach(this::saveModifyDetail7); // repairBackBillDao.findAll().forEach(this::saveModifyDetail7);
deviceUseReportDao.findAll().forEach(this::saveModifyDetail8); // deviceUseReportDao.findAll().forEach(this::saveModifyDetail8);
matchingDeviceLibraryDao.findAll().forEach(this::saveModifyDetail9); // matchingDeviceLibraryDao.findAll().forEach(this::saveModifyDetail9);
} // }
//
//
private void saveModifyDetail1(AllotBill allotBill) { // private void saveModifyDetail1(AllotBill allotBill) {
String receiveUnit = allotBill.getReceiveUnit(); // String receiveUnit = allotBill.getReceiveUnit();
String sendUnit = allotBill.getSendUnit(); // String sendUnit = allotBill.getSendUnit();
//
Integer receiveUnitId = getUnitId(receiveUnit); // Integer receiveUnitId = getUnitId(receiveUnit);
Integer sendUnitId = getUnitId(sendUnit); // Integer sendUnitId = getUnitId(sendUnit);
//
if (receiveUnitId != -1 && sendUnitId != -1) { // if (receiveUnitId != -1 && sendUnitId != -1) {
allotBill.setReceiveUnitId(receiveUnitId); // allotBill.setReceiveUnitId(receiveUnitId);
allotBill.setSendUnitId(sendUnitId); // allotBill.setSendUnitId(sendUnitId);
log.info("[配发] 修正allotBill历史数据,修正的发件单位:{},修正的接收单位:{},发送单位id:{},接收单位id:{}", // log.info("[配发] 修正allotBill历史数据,修正的发件单位:{},修正的接收单位:{},发送单位id:{},接收单位id:{}",
sendUnit, receiveUnit,sendUnitId,receiveUnitId); // sendUnit, receiveUnit,sendUnitId,receiveUnitId);
allotBillDao.save(allotBill); // allotBillDao.save(allotBill);
} // }
//
} // }
//
private void saveModifyDetail2(AllotBackBill allotBackBill) { // private void saveModifyDetail2(AllotBackBill allotBackBill) {
String receiveUnit = allotBackBill.getReceiveUnit(); // String receiveUnit = allotBackBill.getReceiveUnit();
String sendUnit = allotBackBill.getSendUnit(); // String sendUnit = allotBackBill.getSendUnit();
//
Integer receiveUnitId = getUnitId(receiveUnit); // Integer receiveUnitId = getUnitId(receiveUnit);
Integer sendUnitId = getUnitId(sendUnit); // Integer sendUnitId = getUnitId(sendUnit);
//
if (receiveUnitId != -1 && sendUnitId != -1) { // if (receiveUnitId != -1 && sendUnitId != -1) {
allotBackBill.setReceiveUnitId(receiveUnitId); // allotBackBill.setReceiveUnitId(receiveUnitId);
allotBackBill.setSendUnitId(sendUnitId); // allotBackBill.setSendUnitId(sendUnitId);
log.info("[退回] 修正allotBill历史数据,修正的发件单位:{},修正的接收单位:{},发送单位id:{},接收单位id:{}", // log.info("[退回] 修正allotBill历史数据,修正的发件单位:{},修正的接收单位:{},发送单位id:{},接收单位id:{}",
sendUnit, receiveUnit,sendUnitId,receiveUnitId); // sendUnit, receiveUnit,sendUnitId,receiveUnitId);
allotBackBillDao.save(allotBackBill); // allotBackBillDao.save(allotBackBill);
} // }
//
} // }
//
private void saveModifyDetail3(SelfCheckBill selfCheckBill) { // private void saveModifyDetail3(SelfCheckBill selfCheckBill) {
String receiveUnit = selfCheckBill.getCheckUnit(); // String receiveUnit = selfCheckBill.getCheckUnit();
Integer receiveUnitId = getUnitId(receiveUnit); // Integer receiveUnitId = getUnitId(receiveUnit);
if (receiveUnitId != -1) { // if (receiveUnitId != -1) {
selfCheckBill.setCheckUnitId(receiveUnitId); // selfCheckBill.setCheckUnitId(receiveUnitId);
log.info("[自查] 修正selfCheckBill历史数据,修正的单位:{},接收单位id:{}", // log.info("[自查] 修正selfCheckBill历史数据,修正的单位:{},接收单位id:{}",
receiveUnit,receiveUnitId); // receiveUnit,receiveUnitId);
selfCheckBillDao.save(selfCheckBill); // selfCheckBillDao.save(selfCheckBill);
} // }
//
} // }
//
private void saveModifyDetail4(RepairBill allotBill) { // private void saveModifyDetail4(RepairBill allotBill) {
String receiveUnit = allotBill.getReceiveUnit(); // String receiveUnit = allotBill.getReceiveUnit();
String sendUnit = allotBill.getSendUnit(); // String sendUnit = allotBill.getSendUnit();
//
Integer receiveUnitId = getUnitId(receiveUnit); // Integer receiveUnitId = getUnitId(receiveUnit);
Integer sendUnitId = getUnitId(sendUnit); // Integer sendUnitId = getUnitId(sendUnit);
//
if (receiveUnitId != -1 && sendUnitId != -1) { // if (receiveUnitId != -1 && sendUnitId != -1) {
allotBill.setReceiveUnitId(receiveUnitId); // allotBill.setReceiveUnitId(receiveUnitId);
allotBill.setSendUnitId(sendUnitId); // allotBill.setSendUnitId(sendUnitId);
log.info("[维修] 修正RepairBill历史数据,修正的发件单位:{},修正的接收单位:{},发送单位id:{},接收单位id:{}", // log.info("[维修] 修正RepairBill历史数据,修正的发件单位:{},修正的接收单位:{},发送单位id:{},接收单位id:{}",
sendUnit, receiveUnit,sendUnitId,receiveUnitId); // sendUnit, receiveUnit,sendUnitId,receiveUnitId);
repairBillDao.save(allotBill); // repairBillDao.save(allotBill);
} // }
//
} // }
//
private void saveModifyDetail5(RepairSendBill allotBill) { // private void saveModifyDetail5(RepairSendBill allotBill) {
String receiveUnit = allotBill.getReceiveUnit(); // String receiveUnit = allotBill.getReceiveUnit();
String sendUnit = allotBill.getSendUnit(); // String sendUnit = allotBill.getSendUnit();
//
Integer receiveUnitId = getUnitId(receiveUnit); // Integer receiveUnitId = getUnitId(receiveUnit);
Integer sendUnitId = getUnitId(sendUnit); // Integer sendUnitId = getUnitId(sendUnit);
//
if (receiveUnitId != -1 && sendUnitId != -1) { // if (receiveUnitId != -1 && sendUnitId != -1) {
allotBill.setReceiveUnitId(receiveUnitId); // allotBill.setReceiveUnitId(receiveUnitId);
allotBill.setSendUnitId(sendUnitId); // allotBill.setSendUnitId(sendUnitId);
log.info("[送修] 修正RepairSendBill历史数据,修正的发件单位:{},修正的接收单位:{},发送单位id:{},接收单位id:{}", // log.info("[送修] 修正RepairSendBill历史数据,修正的发件单位:{},修正的接收单位:{},发送单位id:{},接收单位id:{}",
sendUnit, receiveUnit,sendUnitId,receiveUnitId); // sendUnit, receiveUnit,sendUnitId,receiveUnitId);
repairSendBillDao.save(allotBill); // repairSendBillDao.save(allotBill);
} // }
//
} // }
//
private void saveModifyDetail6(RepairDetail allotBill) { // private void saveModifyDetail6(RepairDetail allotBill) {
String receiveUnit = allotBill.getLocationUnit(); // String receiveUnit = allotBill.getLocationUnit();
String sendUnit = allotBill.getOwnUnit(); // String sendUnit = allotBill.getOwnUnit();
//
Integer receiveUnitId = getUnitId(receiveUnit); // Integer receiveUnitId = getUnitId(receiveUnit);
Integer sendUnitId = getUnitId(sendUnit); // Integer sendUnitId = getUnitId(sendUnit);
//
if (receiveUnitId != -1 && sendUnitId != -1) { // if (receiveUnitId != -1 && sendUnitId != -1) {
allotBill.setLocationUnitId(receiveUnitId); // allotBill.setLocationUnitId(receiveUnitId);
allotBill.setOwnUnitId(sendUnitId); // allotBill.setOwnUnitId(sendUnitId);
log.info("[维修详情] 修正RepairDetail历史数据,修正的发件单位:{},修正的接收单位:{},发送单位id:{},接收单位id:{}", // log.info("[维修详情] 修正RepairDetail历史数据,修正的发件单位:{},修正的接收单位:{},发送单位id:{},接收单位id:{}",
sendUnit, receiveUnit,sendUnitId,receiveUnitId); // sendUnit, receiveUnit,sendUnitId,receiveUnitId);
repairDetailDao.save(allotBill); // repairDetailDao.save(allotBill);
} // }
//
} // }
private void saveModifyDetail7(RepairBackBill allotBill) { // private void saveModifyDetail7(RepairBackBill allotBill) {
String receiveUnit = allotBill.getReceiveUnit(); // String receiveUnit = allotBill.getReceiveUnit();
String sendUnit = allotBill.getSendUnit(); // String sendUnit = allotBill.getSendUnit();
//
Integer receiveUnitId = getUnitId(receiveUnit); // Integer receiveUnitId = getUnitId(receiveUnit);
Integer sendUnitId = getUnitId(sendUnit); // Integer sendUnitId = getUnitId(sendUnit);
//
if (receiveUnitId != -1 && sendUnitId != -1) { // if (receiveUnitId != -1 && sendUnitId != -1) {
allotBill.setReceiveUnitId(receiveUnitId); // allotBill.setReceiveUnitId(receiveUnitId);
allotBill.setSendUnitId(sendUnitId); // allotBill.setSendUnitId(sendUnitId);
log.info("[维修退回] 修正RepairBackBill历史数据,修正的发件单位:{},修正的接收单位:{},发送单位id:{},接收单位id:{}", // log.info("[维修退回] 修正RepairBackBill历史数据,修正的发件单位:{},修正的接收单位:{},发送单位id:{},接收单位id:{}",
sendUnit, receiveUnit,sendUnitId,receiveUnitId); // sendUnit, receiveUnit,sendUnitId,receiveUnitId);
repairBackBillDao.save(allotBill); // repairBackBillDao.save(allotBill);
} // }
//
} // }
//
private void saveModifyDetail8(DeviceUseReport allotBill) { // private void saveModifyDetail8(DeviceUseReport allotBill) {
String receiveUnit = allotBill.getUnit(); // String receiveUnit = allotBill.getUnit();
Integer receiveUnitId = getUnitId(receiveUnit); // Integer receiveUnitId = getUnitId(receiveUnit);
if (receiveUnitId != -1 ) { // if (receiveUnitId != -1 ) {
allotBill.setUnitId(receiveUnitId); // allotBill.setUnitId(receiveUnitId);
log.info("[用户使用报告] 修正DeviceUseReport历史数据,修正的单位:{},接收单位id:{}", // log.info("[用户使用报告] 修正DeviceUseReport历史数据,修正的单位:{},接收单位id:{}",
receiveUnit,receiveUnitId); // receiveUnit,receiveUnitId);
deviceUseReportDao.save(allotBill); // deviceUseReportDao.save(allotBill);
} // }
//
} // }
//
private void saveModifyDetail9(MatchingDeviceLibrary matchingDeviceLibrary) { // private void saveModifyDetail9(MatchingDeviceLibrary matchingDeviceLibrary) {
String createUnit = matchingDeviceLibrary.getCreateUnit(); // String createUnit = matchingDeviceLibrary.getCreateUnit();
Integer createUnitId = getUnitId(createUnit); // Integer createUnitId = getUnitId(createUnit);
if (createUnitId != -1 ) { // if (createUnitId != -1 ) {
matchingDeviceLibrary.setCreateUnitId(createUnitId); // matchingDeviceLibrary.setCreateUnitId(createUnitId);
log.info("[配套设备库] 修正MatchingDeviceLibrary历史数据,修正的单位:{},接收单位id:{}", // log.info("[配套设备库] 修正MatchingDeviceLibrary历史数据,修正的单位:{},接收单位id:{}",
createUnit,createUnitId); // createUnit,createUnitId);
matchingDeviceLibraryDao.save(matchingDeviceLibrary); // matchingDeviceLibraryDao.save(matchingDeviceLibrary);
} // }
//
} // }
//
private Integer getUnitId(String unitName) { // private Integer getUnitId(String unitName) {
List<Units> units = unitsDao.findAllByName(unitName).orElse(Collections.emptyList()); // List<Units> units = unitsDao.findAllByName(unitName).orElse(Collections.emptyList());
return units.size() == 1 ? units.get(0).getUnitId() : -1; // return units.size() == 1 ? units.get(0).getUnitId() : -1;
} // }
//
// @Bean //// @Bean
// @DependsOn("userUtils") //// @DependsOn("userUtils")
@PostConstruct // @PostConstruct
public void init2(){ // public void init2(){
log.info("单位名称初始化-----");
initCheckDetailUnitName();
initCheckDetailUnitName2();
}
@Autowired
private DeviceCheckDetailDao
deviceCheckDetailDao;
private void initCheckDetailUnitName2() {
// 对现有的数据补充unitId信息
deviceCheckDetailDao.findAll().forEach(this::saveModifyDetail);
}
private void saveModifyDetail(DeviceCheckDetail deviceCheckDetail) {
String checkUnit = deviceCheckDetail.getCheckUnit();
Integer unitId = getUnitId(checkUnit);
if (unitId != -1) {
deviceCheckDetail.setCheckUnitId(unitId);
log.info("[核查] 修正detail历史数据,修正的单位:{},单位id:{}", checkUnit, unitId);
deviceCheckDetailDao.save(deviceCheckDetail);
}
}
// @Override
// @Order(value = 1)
// public void run(String... args) throws Exception {
// log.info("单位名称初始化-----"); // log.info("单位名称初始化-----");
// initCheckDetailUnitName(); // initCheckDetailUnitName();
// initCheckDetailUnitName2();
// }
//
// @Autowired
// private DeviceCheckDetailDao
// deviceCheckDetailDao;
//
// private void initCheckDetailUnitName2() {
// // 对现有的数据补充unitId信息
// deviceCheckDetailDao.findAll().forEach(this::saveModifyDetail);
// }
//
// private void saveModifyDetail(DeviceCheckDetail deviceCheckDetail) {
// String checkUnit = deviceCheckDetail.getCheckUnit();
// Integer unitId = getUnitId(checkUnit);
// if (unitId != -1) {
// deviceCheckDetail.setCheckUnitId(unitId);
// log.info("[核查] 修正detail历史数据,修正的单位:{},单位id:{}", checkUnit, unitId);
// deviceCheckDetailDao.save(deviceCheckDetail);
// }
// } // }
} //// @Override
//// @Order(value = 1)
//// public void run(String... args) throws Exception {
//// log.info("单位名称初始化-----");
//// initCheckDetailUnitName();
//// }
//}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论