package cn.com.goldenwater.dcproj.service.impl; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.dao.BisInspMfdpqhTownDao; import cn.com.goldenwater.dcproj.model.BisInspMfdpqhTown; import cn.com.goldenwater.dcproj.param.BisInspMfdpqhTownParam; import cn.com.goldenwater.dcproj.service.BisInspMfdpqhRgstrService; import cn.com.goldenwater.dcproj.service.BisInspMfdpqhTownService; import cn.com.goldenwater.id.util.UuidUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.Optional; import static cn.com.goldenwater.dcproj.util.CheckUtil.check; /** * @author lhc * @date 2021-6-15 */ @Service @Transactional public class BisInspMfdpqhTownServiceImpl extends AbstractCrudService implements BisInspMfdpqhTownService { @Autowired private BisInspMfdpqhTownDao bisInspMfdpqhTownDao; @Autowired private BisInspMfdpqhRgstrService bisInspMfdpqhRgstrService; public BisInspMfdpqhTownServiceImpl(BisInspMfdpqhTownDao bisInspMfdpqhTownDao) { super(bisInspMfdpqhTownDao); this.bisInspMfdpqhTownDao = bisInspMfdpqhTownDao; } @Override public BisInspMfdpqhTown get(String key) { return Optional.ofNullable(super.get(key)).orElseGet(() -> { BisInspMfdpqhTown child = new BisInspMfdpqhTown(); child.setState("1"); child.setIsDuty("1"); child.setIsPlan("1"); child.setIsWarn("1"); child.setIsLogo("1"); child.setIsSend("1"); child.setChkTm(new Date()); return child; }); } @Override public int insert(BisInspMfdpqhTown bisInspMfdpqhTown) { check(StringUtils.isNotBlank(bisInspMfdpqhTown.getRgstrId()), "rgstrId.no"); BisInspMfdpqhTown checkRgstr = bisInspMfdpqhTownDao.get(bisInspMfdpqhTown.getRgstrId()); if (checkRgstr != null) { bisInspMfdpqhTown.setId(checkRgstr.getId()); return update(bisInspMfdpqhTown); } updateRgstrState(bisInspMfdpqhTown); String uuid = UuidUtil.uuid(); bisInspMfdpqhTown.setId(uuid); bisInspMfdpqhTown.setIntm(new Date()); bisInspMfdpqhTown.setUptm(new Date()); bisInspMfdpqhTown.setDataStat("0"); return this.bisInspMfdpqhTownDao.insert(bisInspMfdpqhTown); } @Override public int update(BisInspMfdpqhTown bisInspMfdpqhTown) { // 更新子表 bisInspMfdpqhTown.setUptm(new Date()); int ret = bisInspMfdpqhTownDao.update(bisInspMfdpqhTown); // 更新登记表状态 updateRgstrState(bisInspMfdpqhTown); return ret; } private void updateRgstrState(BisInspMfdpqhTown bisInspMfdpqhTown) { Map map = new HashMap<>(3); map.put("rgstrId", bisInspMfdpqhTown.getRgstrId()); map.put("param", "town"); map.put("state", bisInspMfdpqhTown.getState()); bisInspMfdpqhRgstrService.updateState(map); } @Override public int delete(String id) { return this.bisInspMfdpqhTownDao.delete(id); } }