package cn.com.goldenwater.dcproj.service.impl; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.dao.BisInspMfdpqhCityDao; import cn.com.goldenwater.dcproj.model.BisInspMfdpqhCity; import cn.com.goldenwater.dcproj.param.BisInspMfdpqhCityParam; import cn.com.goldenwater.dcproj.service.BisInspMfdpqhCityService; import cn.com.goldenwater.dcproj.service.BisInspMfdpqhRgstrService; 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 BisInspMfdpqhCityServiceImpl extends AbstractCrudService implements BisInspMfdpqhCityService { @Autowired private BisInspMfdpqhCityDao bisInspMfdpqhCityDao; @Autowired private BisInspMfdpqhRgstrService bisInspMfdpqhRgstrService; public BisInspMfdpqhCityServiceImpl(BisInspMfdpqhCityDao bisInspMfdpqhCityDao) { super(bisInspMfdpqhCityDao); this.bisInspMfdpqhCityDao = bisInspMfdpqhCityDao; } @Override public BisInspMfdpqhCity get(String key) { return Optional.ofNullable(super.get(key)).orElseGet(() -> { BisInspMfdpqhCity child = new BisInspMfdpqhCity(); child.setIsMntRain("1"); child.setIsMntNrml("1"); child.setIsMntMeet("1"); child.setIsMntShare("1"); child.setIsSendDuty("1"); child.setIsSendPub("1"); child.setIsSendWarn("1"); child.setIsSendDuty("1"); child.setIsSendPlan("1"); child.setIsSendTrain("1"); child.setIsRightPub("1"); child.setIsRightLogo("1"); child.setIsRightPlan("1"); child.setIsRightJump("1"); child.setIsRightDuty("1"); child.setChkTm(new Date()); return child; }); } @Override public int insert(BisInspMfdpqhCity bisInspMfdpqhCity) { check(StringUtils.isNotBlank(bisInspMfdpqhCity.getRgstrId()), "rgstrId.no"); BisInspMfdpqhCity checkRgstr = bisInspMfdpqhCityDao.get(bisInspMfdpqhCity.getRgstrId()); if (checkRgstr != null) { bisInspMfdpqhCity.setId(checkRgstr.getId()); return update(bisInspMfdpqhCity); } updateRgstrState(bisInspMfdpqhCity); String uuid = UuidUtil.uuid(); bisInspMfdpqhCity.setId(uuid); bisInspMfdpqhCity.setIntm(new Date()); bisInspMfdpqhCity.setUptm(new Date()); bisInspMfdpqhCity.setDataStat("0"); return this.bisInspMfdpqhCityDao.insert(bisInspMfdpqhCity); } @Override public int update(BisInspMfdpqhCity bisInspMfdpqhCity) { // 更新子表 bisInspMfdpqhCity.setUptm(new Date()); updateRgstrState(bisInspMfdpqhCity); int ret = bisInspMfdpqhCityDao.update(bisInspMfdpqhCity); // 更新登记表状态 updateRgstrState(bisInspMfdpqhCity); return ret; } private void updateRgstrState(BisInspMfdpqhCity bisInspMfdpqhCity) { Map map = new HashMap<>(3); map.put("rgstrId", bisInspMfdpqhCity.getRgstrId()); map.put("param", "city"); map.put("state", bisInspMfdpqhCity.getState()); bisInspMfdpqhRgstrService.updateState(map); } @Override public int delete(String id) { return this.bisInspMfdpqhCityDao.delete(id); } }