f59d4690078f5d441ae665bb788c9f87979d692c.svn-base 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package cn.com.goldenwater.dcproj.service.impl;
  2. import cn.com.goldenwater.core.service.AbstractCrudService;
  3. import cn.com.goldenwater.dcproj.dao.BisInspMfdpqhTownDao;
  4. import cn.com.goldenwater.dcproj.model.BisInspMfdpqhTown;
  5. import cn.com.goldenwater.dcproj.param.BisInspMfdpqhTownParam;
  6. import cn.com.goldenwater.dcproj.service.BisInspMfdpqhRgstrService;
  7. import cn.com.goldenwater.dcproj.service.BisInspMfdpqhTownService;
  8. import cn.com.goldenwater.id.util.UuidUtil;
  9. import org.apache.commons.lang3.StringUtils;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Service;
  12. import org.springframework.transaction.annotation.Transactional;
  13. import java.util.Date;
  14. import java.util.HashMap;
  15. import java.util.Map;
  16. import java.util.Optional;
  17. import static cn.com.goldenwater.dcproj.util.CheckUtil.check;
  18. /**
  19. * @author lhc
  20. * @date 2021-6-15
  21. */
  22. @Service
  23. @Transactional
  24. public class BisInspMfdpqhTownServiceImpl extends AbstractCrudService<BisInspMfdpqhTown, BisInspMfdpqhTownParam> implements BisInspMfdpqhTownService {
  25. @Autowired
  26. private BisInspMfdpqhTownDao bisInspMfdpqhTownDao;
  27. @Autowired
  28. private BisInspMfdpqhRgstrService bisInspMfdpqhRgstrService;
  29. public BisInspMfdpqhTownServiceImpl(BisInspMfdpqhTownDao bisInspMfdpqhTownDao) {
  30. super(bisInspMfdpqhTownDao);
  31. this.bisInspMfdpqhTownDao = bisInspMfdpqhTownDao;
  32. }
  33. @Override
  34. public BisInspMfdpqhTown get(String key) {
  35. return Optional.ofNullable(super.get(key)).orElseGet(() -> {
  36. BisInspMfdpqhTown child = new BisInspMfdpqhTown();
  37. child.setState("1");
  38. child.setIsDuty("1");
  39. child.setIsPlan("1");
  40. child.setIsWarn("1");
  41. child.setIsLogo("1");
  42. child.setIsSend("1");
  43. child.setChkTm(new Date());
  44. return child;
  45. });
  46. }
  47. @Override
  48. public int insert(BisInspMfdpqhTown bisInspMfdpqhTown) {
  49. check(StringUtils.isNotBlank(bisInspMfdpqhTown.getRgstrId()), "rgstrId.no");
  50. BisInspMfdpqhTown checkRgstr = bisInspMfdpqhTownDao.get(bisInspMfdpqhTown.getRgstrId());
  51. if (checkRgstr != null) {
  52. bisInspMfdpqhTown.setId(checkRgstr.getId());
  53. return update(bisInspMfdpqhTown);
  54. }
  55. updateRgstrState(bisInspMfdpqhTown);
  56. String uuid = UuidUtil.uuid();
  57. bisInspMfdpqhTown.setId(uuid);
  58. bisInspMfdpqhTown.setIntm(new Date());
  59. bisInspMfdpqhTown.setUptm(new Date());
  60. bisInspMfdpqhTown.setDataStat("0");
  61. return this.bisInspMfdpqhTownDao.insert(bisInspMfdpqhTown);
  62. }
  63. @Override
  64. public int update(BisInspMfdpqhTown bisInspMfdpqhTown) {
  65. // 更新子表
  66. bisInspMfdpqhTown.setUptm(new Date());
  67. int ret = bisInspMfdpqhTownDao.update(bisInspMfdpqhTown);
  68. // 更新登记表状态
  69. updateRgstrState(bisInspMfdpqhTown);
  70. return ret;
  71. }
  72. private void updateRgstrState(BisInspMfdpqhTown bisInspMfdpqhTown) {
  73. Map<String, Object> map = new HashMap<>(3);
  74. map.put("rgstrId", bisInspMfdpqhTown.getRgstrId());
  75. map.put("param", "town");
  76. map.put("state", bisInspMfdpqhTown.getState());
  77. bisInspMfdpqhRgstrService.updateState(map);
  78. }
  79. @Override
  80. public int delete(String id) {
  81. return this.bisInspMfdpqhTownDao.delete(id);
  82. }
  83. }