5c7506cc31f4c60b5d43ca432d797b4257ea2bcf.svn-base 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package cn.com.goldenwater.dcproj.service.impl;
  2. import cn.com.goldenwater.dcproj.dao.BisInspKeychkqhSectionDao;
  3. import cn.com.goldenwater.dcproj.model.BisInspKeychkqhRegister;
  4. import cn.com.goldenwater.dcproj.model.BisInspKeychkqhSection;
  5. import cn.com.goldenwater.dcproj.param.BisInspKeychkqhSectionParam;
  6. import cn.com.goldenwater.dcproj.service.BisInspKeychkqhRegisterService;
  7. import cn.com.goldenwater.dcproj.service.BisInspKeychkqhSectionService;
  8. import cn.com.goldenwater.core.service.AbstractCrudService;
  9. import cn.com.goldenwater.dcproj.utils.Builder;
  10. import cn.com.goldenwater.dcproj.utils.Constant;
  11. import cn.com.goldenwater.target.CheckException;
  12. import com.github.pagehelper.PageHelper;
  13. import net.bytebuddy.implementation.bytecode.Throw;
  14. import org.apache.commons.lang.StringUtils;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Service;
  17. import org.springframework.transaction.annotation.Transactional;
  18. import cn.com.goldenwater.id.util.UuidUtil;
  19. import java.util.List;
  20. import java.util.Date;
  21. import java.util.Optional;
  22. /**
  23. * @author lhc
  24. * @date 2021-6-25
  25. */
  26. @Service
  27. @Transactional
  28. public class BisInspKeychkqhSectionServiceImpl extends AbstractCrudService<BisInspKeychkqhSection, BisInspKeychkqhSectionParam> implements BisInspKeychkqhSectionService {
  29. @Autowired
  30. private BisInspKeychkqhSectionDao bisInspKeychkqhSectionDao;
  31. @Autowired
  32. private BisInspKeychkqhRegisterService bisInspKeychkqhRegisterService;
  33. public BisInspKeychkqhSectionServiceImpl(BisInspKeychkqhSectionDao bisInspKeychkqhSectionDao) {
  34. super(bisInspKeychkqhSectionDao);
  35. this.bisInspKeychkqhSectionDao = bisInspKeychkqhSectionDao;
  36. }
  37. @Override
  38. public int insert(BisInspKeychkqhSection bisInspKeychkqhSection) {
  39. if (StringUtils.isBlank(bisInspKeychkqhSection.getRegId())){
  40. throw new CheckException("登记表ID为空");
  41. }
  42. if(StringUtils.isBlank(bisInspKeychkqhSection.getNm())){
  43. throw new CheckException("标段名称为空");
  44. }
  45. BisInspKeychkqhRegister rgstr = bisInspKeychkqhRegisterService.get(bisInspKeychkqhSection.getRegId());
  46. if (rgstr == null ){
  47. throw new CheckException("登记表ID有误");
  48. }
  49. String uuid = UuidUtil.uuid(); // 生成uuid
  50. bisInspKeychkqhSection.setId(uuid);
  51. bisInspKeychkqhSection.setObjId(rgstr.getObjId());
  52. bisInspKeychkqhSection.setIntm(new Date());
  53. bisInspKeychkqhSection.setUptm(new Date());
  54. bisInspKeychkqhSection.setDataStat("0");
  55. int ret = this.bisInspKeychkqhSectionDao.insert(bisInspKeychkqhSection);
  56. updateRgstrState(bisInspKeychkqhSection.getRegId());
  57. return ret;
  58. }
  59. void updateRgstrState(String rgstrId) {
  60. BisInspKeychkqhRegister rgstr = bisInspKeychkqhRegisterService.get(rgstrId);
  61. Optional.ofNullable(rgstr).ifPresent(r -> {
  62. if (!Constant.STRING_TWO.equals(r.getState()) &&
  63. !Constant.STRING_ONE.equals(r.getState())) {
  64. r.setUptm(new Date());
  65. r.setState(Constant.STRING_ONE);
  66. bisInspKeychkqhRegisterService.update(r);
  67. }
  68. });
  69. }
  70. @Override
  71. public int update(BisInspKeychkqhSection bisInspKeychkqhSection) {
  72. BisInspKeychkqhSection child =get(bisInspKeychkqhSection.getId());
  73. Optional.ofNullable(child).orElseThrow(() -> new CheckException("未找到此登记表下的标段"));
  74. bisInspKeychkqhSection.setUptm(new Date());
  75. int ret = this.bisInspKeychkqhSectionDao.update(bisInspKeychkqhSection);
  76. updateRgstrState(child.getRegId());
  77. return ret;
  78. }
  79. @Override
  80. public int delete(String id) {
  81. return this.bisInspKeychkqhSectionDao.delete(id);
  82. }
  83. @Override
  84. public List<BisInspKeychkqhSection> listByRegId(String rgstrId) {
  85. return bisInspKeychkqhSectionDao.findList(Builder.of(BisInspKeychkqhSectionParam::new).with(BisInspKeychkqhSectionParam::setRegId , rgstrId).build());
  86. }
  87. }