PtlNewCarJudgeRulesServiceImpl.java 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package com.ydtech.modules.protocol.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  5. import com.ydtech.core.page.HttpResult;
  6. import com.ydtech.core.page.PageResult;
  7. import com.ydtech.modules.protocol.dao.PtlNewCarJudgeRulesMapper;
  8. import com.ydtech.modules.protocol.entity.po.PtlNewCarJudgeRules;
  9. import com.ydtech.modules.protocol.entity.vo.PtlNewCarJudgeRulesVo;
  10. import com.ydtech.modules.protocol.service.PtlNewCarJudgeRulesService;
  11. import com.ydtech.modules.protocol.utils.AssertionUtils;
  12. import com.ydtech.utils.StringUtils;
  13. import org.springframework.beans.BeanUtils;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import java.util.Collections;
  17. import java.util.Date;
  18. import java.util.List;
  19. /**
  20. * @author CXP
  21. * @description 针对表【ptl_new_car_judge_rules(新车判断规则)】的数据库操作Service实现
  22. * @createDate 2023年11月18日22:50:18
  23. */
  24. @Service
  25. public class PtlNewCarJudgeRulesServiceImpl extends ServiceImpl<PtlNewCarJudgeRulesMapper, PtlNewCarJudgeRules>
  26. implements PtlNewCarJudgeRulesService {
  27. @Override
  28. public HttpResult<Object> saveNewCarJudgeRules(PtlNewCarJudgeRulesVo newCarJudgeRulesVo) {
  29. PtlNewCarJudgeRules ptlNewCarJudgeRules = new PtlNewCarJudgeRules();
  30. BeanUtils.copyProperties(newCarJudgeRulesVo, ptlNewCarJudgeRules);
  31. ptlNewCarJudgeRules.setIsEffective("1");
  32. ptlNewCarJudgeRules.setSaveDate(new Date());
  33. boolean b = save(ptlNewCarJudgeRules);
  34. AssertionUtils.isSucceed(b, "保存失败");
  35. return HttpResult.ok("保存成功");
  36. }
  37. @Override
  38. @Transactional
  39. public HttpResult<Object> reviseNewCarJudgeRules(String ruleId, PtlNewCarJudgeRulesVo newCarJudgeRulesVo) {
  40. PtlNewCarJudgeRules newCarJudgeRules = getById(ruleId);
  41. BeanUtils.copyProperties(newCarJudgeRulesVo, newCarJudgeRules);
  42. newCarJudgeRules.setIsEffective("1");
  43. newCarJudgeRules.setSaveDate(new Date());
  44. boolean b = updateById(newCarJudgeRules);
  45. AssertionUtils.isSucceed(b, "修改失败");
  46. return HttpResult.ok("修改成功");
  47. }
  48. @Override
  49. public HttpResult<Object> deleteByRuleId(String ruleId) {
  50. boolean b = removeById(ruleId);
  51. AssertionUtils.isSucceed(b, "删除失败");
  52. return HttpResult.ok("删除成功");
  53. }
  54. @Override
  55. public HttpResult<PageResult<PtlNewCarJudgeRules>> pageNewCarJudgeRules(PtlNewCarJudgeRulesVo newCarJudgeRulesVo) {
  56. Integer pageNum = newCarJudgeRulesVo.getPageNum();
  57. Integer pageSize = newCarJudgeRulesVo.getPageSize();
  58. Page<PtlNewCarJudgeRules> ptlNewCarJudgeRulesPage = new Page<>(pageNum, pageSize);
  59. LambdaQueryWrapper<PtlNewCarJudgeRules> wrapper = new LambdaQueryWrapper<>();
  60. wrapper.eq(StringUtils.isNotEmpty(newCarJudgeRulesVo.getUnitTypeCode()),PtlNewCarJudgeRules::getUnitTypeCode,newCarJudgeRulesVo.getUnitTypeCode());
  61. wrapper.eq(StringUtils.isNotEmpty(newCarJudgeRulesVo.getUnitTypeValue()),PtlNewCarJudgeRules::getUnitTypeValue,newCarJudgeRulesVo.getUnitTypeValue());
  62. wrapper.eq(StringUtils.isNotEmpty(newCarJudgeRulesVo.getCompanyId()),PtlNewCarJudgeRules::getCompanyId,newCarJudgeRulesVo.getCompanyId());
  63. Page<PtlNewCarJudgeRules> newCarJudgeRulesPage = page(ptlNewCarJudgeRulesPage,wrapper);
  64. PageResult<PtlNewCarJudgeRules> ptlNewCarJudgeRulesPageResult = new PageResult<>(pageNum, pageSize, (int) newCarJudgeRulesPage.getTotal(), newCarJudgeRulesPage.getRecords());
  65. return HttpResult.ok(ptlNewCarJudgeRulesPageResult);
  66. }
  67. @Override
  68. public List<PtlNewCarJudgeRules> getByCompanyId(String companyId) {
  69. String code = "000000";
  70. String substring = companyId.substring(0, 5);
  71. String s = substring + code;
  72. List<PtlNewCarJudgeRules> list = lambdaQuery().eq(PtlNewCarJudgeRules::getCompanyId, s).list();
  73. if (list != null && !list.isEmpty()) {
  74. return list;
  75. }
  76. return Collections.emptyList();
  77. }
  78. @Override
  79. public HttpResult<PtlNewCarJudgeRulesVo> getByRuleId(String ruleId) {
  80. PtlNewCarJudgeRulesVo resultVo=new PtlNewCarJudgeRulesVo();
  81. //获取新车规则判断信息
  82. PtlNewCarJudgeRules newCarJudgeRules = getById(ruleId);
  83. BeanUtils.copyProperties(newCarJudgeRules, resultVo);
  84. AssertionUtils.isEmpty(newCarJudgeRules, "没有此新车判断规则");
  85. return HttpResult.ok(resultVo);
  86. }
  87. }