FreightController.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package com.kmall.admin.controller;
  2. import java.util.List;
  3. import java.util.Map;
  4. import com.google.common.collect.ImmutableBiMap;
  5. import com.kmall.admin.dto.CopyFreightDto;
  6. import com.kmall.admin.entity.FreightEntity;
  7. import com.kmall.admin.entity.FreightItemEntity;
  8. import com.kmall.admin.service.FreightService;
  9. import com.kmall.admin.utils.ParamUtils;
  10. import com.kmall.common.utils.*;
  11. import org.apache.shiro.authz.annotation.RequiresPermissions;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.web.bind.annotation.*;
  14. /**
  15. * Controller
  16. *
  17. * @author Scott
  18. * @email
  19. * @date 2017-08-21 21:19:49
  20. */
  21. @RestController
  22. @RequestMapping("freight")
  23. public class FreightController {
  24. @Autowired
  25. private FreightService freightService;
  26. /**
  27. * 查看列表
  28. */
  29. @RequestMapping("/list")
  30. @RequiresPermissions("freight:list")
  31. public R list(@RequestParam Map<String, Object> params) {
  32. ParamUtils.setQueryPowerByRoleType(params, "storeId", "merchSn", "thirdPartyMerchCode");
  33. //查询列表数据
  34. Query query = new Query(params);
  35. List<FreightEntity> freightList = freightService.queryList(query);
  36. int total = freightService.queryTotal(query);
  37. PageUtils pageUtil = new PageUtils(freightList, total, query.getLimit(), query.getPage());
  38. return R.ok().put("page", pageUtil);
  39. }
  40. /**
  41. * 查看信息
  42. */
  43. @RequestMapping("/info/{id}")
  44. @RequiresPermissions("freight:info")
  45. public R info(@PathVariable("id") Integer id) {
  46. FreightEntity freight = freightService.queryObject(id);
  47. return R.ok().put("freight", freight);
  48. }
  49. /**
  50. * 保存
  51. */
  52. @RequestMapping("/save")
  53. @RequiresPermissions("freight:save")
  54. public R save(@RequestBody FreightEntity freight) {
  55. if (freight.getFreightItemEntityList() == null || freight.getFreightItemEntityList().size() == 0) {
  56. throw new RRException("配送区域及运费不能为空");
  57. }
  58. for (FreightItemEntity freightItemEntity : freight.getFreightItemEntityList()) {
  59. if (freightItemEntity != null) {
  60. Map<String, Object> valideDate = MapBeanUtil.fromObject(freightItemEntity);
  61. ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
  62. builder.put("firstPiece", "首件");
  63. builder.put("freight", "运费");
  64. builder.put("continuePiece", "续件");
  65. builder.put("renew", "续费");
  66. R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  67. if (Integer.valueOf(r.get("code").toString()) != 0) {
  68. throw new RRException(r.get("msg").toString());
  69. }
  70. }
  71. }
  72. freightService.save(freight);
  73. return R.ok();
  74. }
  75. /**
  76. * 修改
  77. */
  78. @RequestMapping("/update")
  79. @RequiresPermissions("freight:update")
  80. public R update(@RequestBody FreightEntity freight) {
  81. if (freight.getFreightItemEntityList() == null || freight.getFreightItemEntityList().size() == 0) {
  82. throw new RRException("配送区域及运费不能为空");
  83. }
  84. for (FreightItemEntity freightItemEntity : freight.getFreightItemEntityList()) {
  85. if (freightItemEntity != null) {
  86. Map<String, Object> valideDate = MapBeanUtil.fromObject(freightItemEntity);
  87. ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
  88. builder.put("firstPiece", "首件");
  89. builder.put("freight", "运费");
  90. builder.put("continuePiece", "续件");
  91. builder.put("renew", "续费");
  92. R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  93. if (Integer.valueOf(r.get("code").toString()) != 0) {
  94. throw new RRException(r.get("msg").toString());
  95. }
  96. }
  97. }
  98. freightService.update(freight);
  99. return R.ok();
  100. }
  101. /**
  102. * 删除
  103. */
  104. @RequestMapping("/delete")
  105. @RequiresPermissions("freight:delete")
  106. public R delete(@RequestBody Integer[] ids) {
  107. freightService.deleteBatch(ids);
  108. return R.ok();
  109. }
  110. /**
  111. * 查看所有列表
  112. */
  113. @RequestMapping("/queryAll")
  114. public R queryAll(@RequestParam Map<String, Object> params) {
  115. ParamUtils.setQueryPowerByRoleType(params, "storeId", "merchSn", "thirdPartyMerchCode");
  116. List<FreightEntity> list = freightService.queryList(params);
  117. return R.ok().put("list", list);
  118. }
  119. /**
  120. * 保存
  121. */
  122. @RequestMapping("/saveCopyFreight")
  123. // @RequiresPermissions("freight:saveCopyFreight")
  124. public R saveCopyFreight(@RequestBody CopyFreightDto copyFreightDto) {
  125. freightService.saveCopyFreight(copyFreightDto);
  126. return R.ok();
  127. }
  128. }