WarehouseService.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package com.dk.mdm.service.mst;
  2. import com.dk.common.infrastructure.annotaiton.Pagination;
  3. import com.dk.common.infrastructure.constant.Constant;
  4. import com.dk.common.model.pojo.PageList;
  5. import com.dk.common.response.ResponseResultUtil;
  6. import com.dk.common.response.ResponseResultVO;
  7. import com.dk.mdm.infrastructure.convert.mst.WarehouseConvert;
  8. import com.dk.mdm.infrastructure.util.AuthUtils;
  9. import com.dk.mdm.model.pojo.mst.Warehouse;
  10. import com.dk.mdm.mapper.mst.WarehouseMapper;
  11. import com.dk.common.service.BaseService;
  12. import com.dk.common.mapper.BaseMapper;
  13. import com.dk.mdm.model.query.mst.WarehouseQuery;
  14. import com.dk.mdm.model.response.mst.WarehouseResponse;
  15. import com.dk.mdm.model.vo.mst.WarehouseVO;
  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. @Service
  22. @Transactional
  23. public class WarehouseService extends BaseService<Warehouse> {
  24. @Override
  25. public BaseMapper<Warehouse> getRepository() {
  26. return warehouseMapper;
  27. }
  28. @Autowired
  29. private WarehouseMapper warehouseMapper;
  30. @Autowired
  31. private CommonService commonService;
  32. @Autowired
  33. private WarehouseConvert warehouseConvert;
  34. @Autowired
  35. private AuthUtils authUtils;
  36. /**
  37. * @desc : 重写主键
  38. * @author : 于继渤
  39. * @date : 2024/2/29 20:29
  40. */
  41. @Override
  42. public String getPrimaryKey() {
  43. return "wh_id";
  44. }
  45. /**
  46. * @desc : 查询
  47. * @author : 于继渤
  48. * @date : 2023/1/5 9:39
  49. */
  50. @Pagination
  51. public ResponseResultVO<PageList<WarehouseResponse>> selectByCond(WarehouseQuery warehouseQuery) {
  52. return super.mergeListWithCount(warehouseQuery, warehouseMapper.selectByCond(warehouseQuery),
  53. warehouseMapper.countByCond(warehouseQuery));
  54. }
  55. /**
  56. * @desc : 新建
  57. * @author : 于继渤
  58. * @date : 2023/1/5 9:39
  59. */
  60. @Transactional(
  61. rollbackFor = {Exception.class}
  62. )
  63. public ResponseResultVO<?> insert(WarehouseVO warehouseVO) {
  64. //实体转换
  65. Warehouse warehouse = warehouseConvert.convertToPo(warehouseVO);
  66. //设置序号
  67. warehouse.setDisplayNo(commonService.getMaxDisplayNo(Constant.DisplayNoTable.WAREHOUSE));
  68. //设置编码
  69. Map<String, Object> uniqueNoteCode = commonService.getUniqueNoteCode(Constant.docNameConstant.WAREHOUSE.getName(), true);
  70. warehouse.setWhId(uniqueNoteCode.get("outId").toString());
  71. warehouse.setWhCode(uniqueNoteCode.get("outNote").toString());
  72. //新建如果是默认取消其他默认
  73. if(warehouseVO.getFlgDefault() != null ){
  74. //默认 把其他置为非默认
  75. warehouseMapper.updateFlgDefault(authUtils.getStaff().getCpId());
  76. }
  77. //新建
  78. warehouseMapper.insert(warehouse);
  79. return ResponseResultUtil.success(warehouse);
  80. }
  81. /**
  82. * @desc : 编辑
  83. * @author : 于继渤
  84. * @date : 2023/1/5 9:39
  85. */
  86. @Transactional(
  87. rollbackFor = {Exception.class}
  88. )
  89. public ResponseResultVO<?> update(WarehouseVO warehouseVO) {
  90. Warehouse warehouse1 = warehouseMapper.selectById(warehouseVO.getWhId());
  91. if ((warehouse1.getFlgDefault() == null || !warehouse1.getFlgDefault()) && warehouseVO.getFlgDefault() != null && warehouseVO.getFlgDefault()) {
  92. //默认 把其他置为非默认
  93. warehouseMapper.updateFlgDefault(warehouseVO.getCpId());
  94. }
  95. Warehouse warehouse = warehouseConvert.convertToPo(warehouseVO);
  96. super.updateByUuid(warehouse);
  97. return ResponseResultUtil.success();
  98. }
  99. /**
  100. * @desc : 编辑
  101. * @author : 于继渤
  102. * @date : 2023/1/5 9:39
  103. */
  104. @Transactional(
  105. rollbackFor = {Exception.class}
  106. )
  107. public ResponseResultVO<?> updateBatchWarehouseDisplayNo(WarehouseVO warehouseVO) {
  108. warehouseMapper.updateBatchWarehouseDisplayNo(warehouseVO.getDataIds());
  109. return ResponseResultUtil.success();
  110. }
  111. }