package com.ydtech.modules.protocol.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ydtech.core.page.HttpResult; import com.ydtech.core.page.PageResult; import com.ydtech.modules.protocol.dao.PtlNewCarJudgeRulesMapper; import com.ydtech.modules.protocol.entity.po.PtlNewCarJudgeRules; import com.ydtech.modules.protocol.entity.vo.PtlNewCarJudgeRulesVo; import com.ydtech.modules.protocol.service.PtlNewCarJudgeRulesService; import com.ydtech.modules.protocol.utils.AssertionUtils; import com.ydtech.utils.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Collections; import java.util.Date; import java.util.List; /** * @author CXP * @description 针对表【ptl_new_car_judge_rules(新车判断规则)】的数据库操作Service实现 * @createDate 2023年11月18日22:50:18 */ @Service public class PtlNewCarJudgeRulesServiceImpl extends ServiceImpl implements PtlNewCarJudgeRulesService { @Override public HttpResult saveNewCarJudgeRules(PtlNewCarJudgeRulesVo newCarJudgeRulesVo) { PtlNewCarJudgeRules ptlNewCarJudgeRules = new PtlNewCarJudgeRules(); BeanUtils.copyProperties(newCarJudgeRulesVo, ptlNewCarJudgeRules); ptlNewCarJudgeRules.setIsEffective("1"); ptlNewCarJudgeRules.setSaveDate(new Date()); boolean b = save(ptlNewCarJudgeRules); AssertionUtils.isSucceed(b, "保存失败"); return HttpResult.ok("保存成功"); } @Override @Transactional public HttpResult reviseNewCarJudgeRules(String ruleId, PtlNewCarJudgeRulesVo newCarJudgeRulesVo) { PtlNewCarJudgeRules newCarJudgeRules = getById(ruleId); BeanUtils.copyProperties(newCarJudgeRulesVo, newCarJudgeRules); newCarJudgeRules.setIsEffective("1"); newCarJudgeRules.setSaveDate(new Date()); boolean b = updateById(newCarJudgeRules); AssertionUtils.isSucceed(b, "修改失败"); return HttpResult.ok("修改成功"); } @Override public HttpResult deleteByRuleId(String ruleId) { boolean b = removeById(ruleId); AssertionUtils.isSucceed(b, "删除失败"); return HttpResult.ok("删除成功"); } @Override public HttpResult> pageNewCarJudgeRules(PtlNewCarJudgeRulesVo newCarJudgeRulesVo) { Integer pageNum = newCarJudgeRulesVo.getPageNum(); Integer pageSize = newCarJudgeRulesVo.getPageSize(); Page ptlNewCarJudgeRulesPage = new Page<>(pageNum, pageSize); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(StringUtils.isNotEmpty(newCarJudgeRulesVo.getUnitTypeCode()),PtlNewCarJudgeRules::getUnitTypeCode,newCarJudgeRulesVo.getUnitTypeCode()); wrapper.eq(StringUtils.isNotEmpty(newCarJudgeRulesVo.getUnitTypeValue()),PtlNewCarJudgeRules::getUnitTypeValue,newCarJudgeRulesVo.getUnitTypeValue()); wrapper.eq(StringUtils.isNotEmpty(newCarJudgeRulesVo.getCompanyId()),PtlNewCarJudgeRules::getCompanyId,newCarJudgeRulesVo.getCompanyId()); Page newCarJudgeRulesPage = page(ptlNewCarJudgeRulesPage,wrapper); PageResult ptlNewCarJudgeRulesPageResult = new PageResult<>(pageNum, pageSize, (int) newCarJudgeRulesPage.getTotal(), newCarJudgeRulesPage.getRecords()); return HttpResult.ok(ptlNewCarJudgeRulesPageResult); } @Override public List getByCompanyId(String companyId) { String code = "000000"; String substring = companyId.substring(0, 5); String s = substring + code; List list = lambdaQuery().eq(PtlNewCarJudgeRules::getCompanyId, s).list(); if (list != null && !list.isEmpty()) { return list; } return Collections.emptyList(); } @Override public HttpResult getByRuleId(String ruleId) { PtlNewCarJudgeRulesVo resultVo=new PtlNewCarJudgeRulesVo(); //获取新车规则判断信息 PtlNewCarJudgeRules newCarJudgeRules = getById(ruleId); BeanUtils.copyProperties(newCarJudgeRules, resultVo); AssertionUtils.isEmpty(newCarJudgeRules, "没有此新车判断规则"); return HttpResult.ok(resultVo); } }