SalesPromotionController.java 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. package com.ruoyi.app.promotion;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import javax.servlet.http.HttpServletResponse;
  5. import com.alibaba.fastjson.JSONArray;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  8. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  9. import com.ruoyi.app.utils.DateUtil;
  10. import com.ruoyi.app.utils.PayPush;
  11. import com.ruoyi.common.annotation.Anonymous;
  12. import com.ruoyi.common.annotation.RepeatSubmit;
  13. import com.ruoyi.common.utils.StringUtils;
  14. import com.ruoyi.system.domain.PosOrder;
  15. import com.ruoyi.system.mapper.PosOrderMapper;
  16. import com.ruoyi.system.utils.Auth;
  17. import com.ruoyi.system.utils.JwtUtil;
  18. import io.swagger.models.auth.In;
  19. import org.springframework.security.access.prepost.PreAuthorize;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.web.bind.annotation.*;
  22. import com.ruoyi.common.annotation.Log;
  23. import com.ruoyi.common.core.controller.BaseController;
  24. import com.ruoyi.common.core.domain.AjaxResult;
  25. import com.ruoyi.common.enums.BusinessType;
  26. import com.ruoyi.system.domain.SalesPromotion;
  27. import com.ruoyi.system.service.ISalesPromotionService;
  28. import com.ruoyi.common.utils.MessageUtils;
  29. import com.ruoyi.common.utils.poi.ExcelUtil;
  30. import com.ruoyi.common.core.page.TableDataInfo;
  31. import redis.clients.jedis.Jedis;
  32. /**
  33. * SalesPromotionController
  34. *
  35. * @author ruoyi
  36. * @date 2024-05-30
  37. */
  38. @RestController
  39. @RequestMapping("/system/promotion")
  40. public class SalesPromotionController extends BaseController {
  41. @Autowired
  42. private ISalesPromotionService salesPromotionService;
  43. @Autowired
  44. private PosOrderMapper posOrderMapper;
  45. /**
  46. * 获取可参于促销活动
  47. *
  48. * @param mdId
  49. * @param price
  50. * @return
  51. */
  52. @Anonymous
  53. @Auth
  54. @GetMapping("/getorderuzt")
  55. public AjaxResult getorderuzt(@RequestHeader String token,
  56. @RequestParam(defaultValue = "") String mdId,
  57. @RequestParam(defaultValue = "") String price,
  58. @RequestParam(defaultValue = "") String yfPrice) {
  59. System.out.println("getorderuzt");
  60. JwtUtil jwtUtil = new JwtUtil();
  61. String id = jwtUtil.getusid(token);
  62. String language = getLanguage(id);
  63. DateUtil date = new DateUtil();
  64. System.out.println("getorderuzt输出信息用户id:" + id + "语言:" + language + "价格:" + price + "运费:" + yfPrice + "门店id:" + mdId + "当前时间:" + date.GetDateNt());
  65. QueryWrapper<SalesPromotion> wrapper = new QueryWrapper<>();
  66. wrapper.eq("sales_state", 0)
  67. .ge("end_time", date.GetDateNt())
  68. .eq("language", language)
  69. .eq("deleted", '0');
  70. if (!"".equals(mdId)) {
  71. wrapper.and(w -> w.eq("sh_id", mdId).or().isNull("sh_id"));
  72. }
  73. wrapper.and(sub -> {
  74. sub.nested(nonShip ->
  75. nonShip.nested(cond -> cond.le("sales_condition", price)
  76. .or()
  77. .nested(cn -> cn.isNull("sales_condition"))
  78. )
  79. );
  80. }
  81. );
  82. // // 动态构建价格条件
  83. // boolean hasPrice = StringUtils.isNotBlank(price);
  84. // boolean hasYfPrice = StringUtils.isNotBlank(yfPrice);
  85. // if (hasPrice || hasYfPrice) {
  86. // wrapper.and(wrap -> {
  87. // // 非运费条件块(sales_type <> 1)
  88. // if (hasPrice) {
  89. // wrap.and(sub ->
  90. // sub.nested(nonShip ->
  91. // nonShip.nested(cond -> cond.le("sales_condition", price).ne("sales_type", "1"))
  92. // .or()
  93. // .nested(cond -> cond.isNull("sales_condition").ne("sales_type", "1"))
  94. // )
  95. // );
  96. // }
  97. //
  98. // // 运费条件块(sales_type = 1)
  99. // if (hasYfPrice) {
  100. // wrap.or(sub ->
  101. // sub.nested(ship ->
  102. // ship.nested(cond -> cond.le("sales_condition", yfPrice).eq("sales_type", "1"))
  103. // .or()
  104. // .nested(cond -> cond.isNull("sales_condition").eq("sales_type", "1"))
  105. // )
  106. // );
  107. // }
  108. // });
  109. // }
  110. List<SalesPromotion> saleslist = salesPromotionService.list(wrapper);
  111. JSONArray array = new JSONArray();
  112. for (SalesPromotion promotion : saleslist) {
  113. if (promotion.getSalesFund() == null) {
  114. array.add(promotion);
  115. } else {
  116. int sycs = posOrderMapper.getActivity(Long.valueOf(id), promotion.getId());
  117. if (sycs < promotion.getSalesFund().intValue()) {
  118. array.add(promotion);
  119. }
  120. }
  121. }
  122. return success(array);
  123. }
  124. private String getLanguage(String uid) {
  125. Jedis jedis = new Jedis("localhost", 6379);
  126. String lang = jedis.get(uid);
  127. System.out.println("从redis获取的语言是:" + lang);
  128. String result = "0";
  129. if ("zh-CN".equals(lang)) {
  130. result = "2";
  131. }
  132. if ("zh-TW".equals(lang)) {
  133. result = "3";
  134. }
  135. if ("en-US".equals(lang)) {
  136. result = "1";
  137. }
  138. System.out.println("获取的语言是:" + result);
  139. return result;
  140. }
  141. /**
  142. * 查询SalesPromotion列表
  143. */
  144. @PreAuthorize("@ss.hasPermi('system:promotion:list')")
  145. @GetMapping("/list")
  146. public TableDataInfo list(SalesPromotion salesPromotion) {
  147. startPage();
  148. List<SalesPromotion> list = salesPromotionService.selectSalesPromotionList(salesPromotion);
  149. return getDataTable(list);
  150. }
  151. /**
  152. * 导出SalesPromotion列表
  153. */
  154. @PreAuthorize("@ss.hasPermi('system:promotion:export')")
  155. @Log(title = "SalesPromotion", businessType = BusinessType.EXPORT)
  156. @PostMapping("/export")
  157. public void export(HttpServletResponse response, SalesPromotion salesPromotion) {
  158. List<SalesPromotion> list = salesPromotionService.selectSalesPromotionList(salesPromotion);
  159. ExcelUtil<SalesPromotion> util = new ExcelUtil<SalesPromotion>(SalesPromotion.class);
  160. util.exportExcel(response, list, MessageUtils.message("no.export.excel.salespromotion"));
  161. }
  162. /**
  163. * 获取SalesPromotion详细信息
  164. */
  165. @PreAuthorize("@ss.hasPermi('system:promotion:query')")
  166. @GetMapping(value = "/{id}")
  167. public AjaxResult getInfo(@PathVariable("id") Long id) {
  168. SalesPromotion result = salesPromotionService.selectSalesPromotionById(id);
  169. if (result != null) {
  170. LambdaQueryWrapper<PosOrder> query = new LambdaQueryWrapper<>();
  171. query.nested(w -> w.eq(PosOrder::getActivity, id).or().eq(PosOrder::getMdActivity, id));
  172. boolean exist = posOrderMapper.selectCount(query) > 0;
  173. if (exist) {
  174. result.setEdit(!exist);
  175. } else {
  176. result.setEdit(true);
  177. }
  178. }
  179. return success(result);
  180. }
  181. /**
  182. * 新增SalesPromotion
  183. */
  184. @PreAuthorize("@ss.hasPermi('system:promotion:add')")
  185. @Log(title = "SalesPromotion", businessType = BusinessType.INSERT)
  186. @PostMapping
  187. public AjaxResult add(@RequestBody SalesPromotion salesPromotion) {
  188. return toAjax(salesPromotionService.insertSalesPromotion(salesPromotion));
  189. }
  190. /**
  191. * 修改SalesPromotion
  192. */
  193. @PreAuthorize("@ss.hasPermi('system:promotion:edit')")
  194. @Log(title = "SalesPromotion", businessType = BusinessType.UPDATE)
  195. @PutMapping
  196. public AjaxResult edit(@RequestBody SalesPromotion salesPromotion) {
  197. return toAjax(salesPromotionService.updateSalesPromotion(salesPromotion));
  198. }
  199. /**
  200. * 删除SalesPromotion
  201. */
  202. @PreAuthorize("@ss.hasPermi('system:promotion:remove')")
  203. @Log(title = "SalesPromotion", businessType = BusinessType.DELETE)
  204. @DeleteMapping("/{ids}")
  205. public AjaxResult remove(@PathVariable Long[] ids) {
  206. return toAjax(salesPromotionService.deleteSalesPromotionByIds(ids));
  207. }
  208. }