MoneyAccountService.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package com.dk.mdm.service.mst;
  2. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  3. import com.dk.common.infrastructure.annotaiton.Pagination;
  4. import com.dk.common.infrastructure.constant.Constant;
  5. import com.dk.common.model.pojo.PageList;
  6. import com.dk.common.response.ResponseResultUtil;
  7. import com.dk.common.response.ResponseResultVO;
  8. import com.dk.mdm.infrastructure.convert.mst.MoneyAccountConvert;
  9. import com.dk.mdm.model.pojo.mst.MoneyAccount;
  10. import com.dk.mdm.mapper.mst.MoneyAccountMapper;
  11. import com.dk.common.service.BaseService;
  12. import com.dk.common.mapper.BaseMapper;
  13. import com.dk.mdm.model.query.mst.MoneyAccountQuery;
  14. import com.dk.mdm.model.response.mst.MoneyAccountResponse;
  15. import com.dk.mdm.model.vo.mst.MoneyAccountVO;
  16. import com.dk.mdm.service.common.CommonService;
  17. import org.springframework.stereotype.Service;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.transaction.annotation.Transactional;
  20. import java.util.Map;
  21. import java.util.UUID;
  22. @Service
  23. @Transactional
  24. public class MoneyAccountService extends BaseService<MoneyAccount> {
  25. @Override
  26. public BaseMapper<MoneyAccount> getRepository() {
  27. return moneyAccountMapper;
  28. }
  29. @Autowired
  30. private MoneyAccountMapper moneyAccountMapper;
  31. @Autowired
  32. private MoneyAccountConvert moneyAccountConvert;
  33. @Autowired
  34. private CommonService commonService;
  35. /**
  36. * @desc : 重写主键
  37. * @author : 宋扬
  38. * @date : 2023/1/9 10:39
  39. */
  40. @Override
  41. public String getPrimaryKey() {
  42. return "mac_id";
  43. }
  44. /**
  45. * @desc : 条件查询
  46. * @author : 宋扬
  47. * @date : 2023/2/29 10:40
  48. */
  49. @Pagination
  50. public ResponseResultVO<PageList<MoneyAccountResponse>> selectByCond(MoneyAccountQuery moneyAccountQuery) {
  51. return super.mergeListWithCount(moneyAccountQuery, moneyAccountMapper.selectByCond(moneyAccountQuery),
  52. moneyAccountMapper.countByCond(moneyAccountQuery));
  53. }
  54. /**
  55. * @desc : 保存方法
  56. * @author : 宋扬
  57. * @date : 2023/2/29 10:49
  58. */
  59. @Transactional(
  60. rollbackFor = {Exception.class}
  61. )
  62. public ResponseResultVO<?> insert(MoneyAccountVO moneyAccountVO) {
  63. // 转化实体
  64. MoneyAccount moneyAccount = moneyAccountConvert.convertToPo(moneyAccountVO);
  65. Integer displayNo = moneyAccountMapper.selectDisplayNo(new MoneyAccountQuery());
  66. if (displayNo != null) {
  67. //插入序号
  68. moneyAccount.setDisplayNo(displayNo);
  69. } else {
  70. moneyAccount.setDisplayNo(0);
  71. }
  72. // 获取编码和主键UuId
  73. Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.MONEYACCOUNT.getName(),true);
  74. moneyAccount.setMacId(codeMap.get("outId").toString());
  75. moneyAccount.setMacCode(codeMap.get("outNote").toString());
  76. return super.insert(moneyAccount);
  77. }
  78. /**
  79. * @desc : 编辑方法
  80. * @author : 宋扬
  81. * @date : 2023/2/29 10:49
  82. */
  83. @Transactional(
  84. rollbackFor = {Exception.class}
  85. )
  86. public ResponseResultVO<Boolean> update(MoneyAccountVO moneyAccountVO) {
  87. // 转化实体
  88. MoneyAccount moneyAccount = moneyAccountConvert.convertToPo(moneyAccountVO);
  89. return ResponseResultUtil.success(super.update(moneyAccount, new UpdateWrapper<MoneyAccount>().lambda().eq(MoneyAccount::getMacId,
  90. UUID.fromString(moneyAccount.getMacId()))));
  91. }
  92. }