ReplacementInstrumentActivityController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. package com.ym.mec.web.controller;
  2. import com.beust.jcommander.internal.Lists;
  3. import com.ym.mec.auth.api.client.SysUserFeignService;
  4. import com.ym.mec.biz.dal.dao.ReplacementInstrumentActivityDao;
  5. import com.ym.mec.biz.dal.dao.SysConfigDao;
  6. import com.ym.mec.biz.dal.dto.ReplacementInstrumentActivityStatDto;
  7. import com.ym.mec.biz.dal.entity.Goods;
  8. import com.ym.mec.biz.dal.entity.ReplacementInstrumentActivity;
  9. import com.ym.mec.biz.dal.entity.ReplacementInstrumentCooperation;
  10. import com.ym.mec.biz.dal.enums.MessageTypeEnum;
  11. import com.ym.mec.biz.dal.enums.YesOrNoEnum;
  12. import com.ym.mec.biz.dal.page.ReplacementInstrumentActivityQueryInfo;
  13. import com.ym.mec.biz.service.*;
  14. import com.ym.mec.common.controller.BaseController;
  15. import com.ym.mec.common.entity.HttpResponseResult;
  16. import com.ym.mec.common.exception.BizException;
  17. import com.ym.mec.common.page.PageInfo;
  18. import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
  19. import com.ym.mec.util.date.DateUtil;
  20. import com.ym.mec.util.excel.POIUtil;
  21. import com.ym.mec.util.http.HttpUtil;
  22. import io.swagger.annotations.Api;
  23. import io.swagger.annotations.ApiOperation;
  24. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.security.access.prepost.PreAuthorize;
  27. import org.springframework.web.bind.annotation.GetMapping;
  28. import org.springframework.web.bind.annotation.PostMapping;
  29. import org.springframework.web.bind.annotation.RequestMapping;
  30. import org.springframework.web.bind.annotation.RestController;
  31. import javax.servlet.http.HttpServletResponse;
  32. import java.io.IOException;
  33. import java.io.OutputStream;
  34. import java.util.Date;
  35. import java.util.HashMap;
  36. import java.util.Map;
  37. @RequestMapping("${app-config.url.web:}/replacementInstrumentActivity")
  38. @Api(tags = "乐器置换-调查问卷服务")
  39. @RestController
  40. public class ReplacementInstrumentActivityController extends BaseController {
  41. @Autowired
  42. private ReplacementInstrumentActivityService replacementInstrumentActivityService;
  43. @Autowired
  44. private OrganizationService organizationService;
  45. @Autowired
  46. private ReplacementInstrumentActivityDao replacementInstrumentActivityDao;
  47. @Autowired
  48. private ReplacementInstrumentCooperationService replacementInstrumentCooperationService;
  49. @Autowired
  50. private SysConfigDao sysConfigDao;
  51. @Autowired
  52. private SysMessageService sysMessageService;
  53. @Autowired
  54. private GoodsService goodsService;
  55. @ApiOperation(value = "分页查询列表")
  56. @GetMapping("/queryPage")
  57. @PreAuthorize("@pcs.hasPermissions('replacementInstrumentActivity/queryPage')")
  58. public HttpResponseResult<PageInfo<ReplacementInstrumentActivityStatDto>> queryPage(ReplacementInstrumentActivityQueryInfo queryInfo) {
  59. queryInfo.setOrganId(organizationService.getEmployeeOrgan(queryInfo.getOrganId()));
  60. return succeed(replacementInstrumentActivityService.getPageList(queryInfo));
  61. }
  62. @ApiOperation(value = "统计信息查询")
  63. @GetMapping("/queryReplacementsStat")
  64. public HttpResponseResult<PageInfo<ReplacementInstrumentActivityStatDto>> queryReplacementsStat(ReplacementInstrumentActivityQueryInfo queryInfo) {
  65. return succeed(replacementInstrumentActivityService.queryReplacementsStat(queryInfo));
  66. }
  67. @ApiOperation(value = "统计信息查询")
  68. @GetMapping("/resultSync")
  69. public void resultSync() {
  70. replacementInstrumentActivityService.resultSync();
  71. }
  72. @ApiOperation(value = "修改")
  73. @PostMapping("/update")
  74. @PreAuthorize("@pcs.hasPermissions('replacementInstrumentActivity/update')")
  75. public HttpResponseResult<ReplacementInstrumentActivity> update(ReplacementInstrumentActivity replacementInstrumentActivity) {
  76. replacementInstrumentActivity.setGoodsId(replacementInstrumentActivity.getInstrumentsId());
  77. ReplacementInstrumentActivity oldReplacementInstrumentActivity = replacementInstrumentActivityDao.getLock(replacementInstrumentActivity.getId());
  78. if (!oldReplacementInstrumentActivity.getPayStatus().equals(0)) {
  79. return failed("支付中、已支付的乐器置换,不能修改");
  80. }
  81. ReplacementInstrumentCooperation byCooperationId = replacementInstrumentCooperationService.get(oldReplacementInstrumentActivity.getReplacementInstrumentCooperationId());
  82. if (byCooperationId.getOpenPay().equals(YesOrNoEnum.YES) && oldReplacementInstrumentActivity.getInstrumentsId() == null && replacementInstrumentActivity.getInstrumentsId() != null) {
  83. Goods goods = goodsService.get(replacementInstrumentActivity.getInstrumentsId());
  84. goods.setBrand(goodsService.getBrandMap().getOrDefault(goods.getBrand(),goods.getBrand()));
  85. Map<Integer, String> userMap = new HashMap<>();
  86. Map<Integer, String> userPhoneMap = new HashMap<>();
  87. Integer userId = oldReplacementInstrumentActivity.getUserId();
  88. String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
  89. String pushUrl = baseApiUrl + "/#/questionGoodsSale?id=";
  90. userMap.put(userId, userId.toString());
  91. sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.STUDENT_SMS_PUSH_REPLACEMENT_PAY,
  92. userMap, null, 0, "5?" + pushUrl + replacementInstrumentActivity.getId(), "STUDENT", goods.getBrand(), "");
  93. userPhoneMap.put(userId, oldReplacementInstrumentActivity.getMobileNo());
  94. sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS, MessageTypeEnum.STUDENT_SMS_PUSH_REPLACEMENT_PAY,
  95. userPhoneMap, null, 0, null, null, goods.getBrand(), HttpUtil.getSortUrl(pushUrl + replacementInstrumentActivity.getId()));
  96. }
  97. oldReplacementInstrumentActivity.setSubjectId(replacementInstrumentActivity.getSubjectId());
  98. oldReplacementInstrumentActivity.setInstrumentsId(replacementInstrumentActivity.getInstrumentsId());
  99. oldReplacementInstrumentActivity.setGoodsId(replacementInstrumentActivity.getInstrumentsId());
  100. oldReplacementInstrumentActivity.setUpdateTime(new Date());
  101. replacementInstrumentActivityService.update(oldReplacementInstrumentActivity);
  102. return succeed(replacementInstrumentActivity);
  103. }
  104. @ApiOperation(value = "开启/关闭缴费")
  105. @PostMapping("/updateOpenFlag")
  106. @PreAuthorize("@pcs.hasPermissions('replacementInstrumentActivity/updateOpenFlag')")
  107. public HttpResponseResult<ReplacementInstrumentActivity> updateOpenFlag(Integer Id,Integer openFlag) {
  108. ReplacementInstrumentActivity replacementInstrumentActivity = replacementInstrumentActivityDao.getLock(Id);
  109. if (!replacementInstrumentActivity.getPayStatus().equals(0)) {
  110. return failed("支付中、已支付的乐器置换,不能修改");
  111. }
  112. if(replacementInstrumentActivity.getInstrumentsId() == null){
  113. return failed("修改失败:用户没有可置换商品");
  114. }
  115. if (openFlag == 1) {
  116. Goods goods = goodsService.get(replacementInstrumentActivity.getInstrumentsId());
  117. goods.setBrand(goodsService.getBrandMap().getOrDefault(goods.getBrand(),goods.getBrand()));
  118. Map<Integer, String> userMap = new HashMap<>();
  119. Map<Integer, String> userPhoneMap = new HashMap<>();
  120. Integer userId = replacementInstrumentActivity.getUserId();
  121. String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
  122. String pushUrl = baseApiUrl + "/#/questionGoodsSale?id=";
  123. userMap.put(userId, userId.toString());
  124. sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.STUDENT_SMS_PUSH_REPLACEMENT_PAY,
  125. userMap, null, 0, "5?" + pushUrl + replacementInstrumentActivity.getId(), "STUDENT", goods.getBrand(), "");
  126. userPhoneMap.put(userId, replacementInstrumentActivity.getMobileNo());
  127. sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS, MessageTypeEnum.STUDENT_SMS_PUSH_REPLACEMENT_PAY,
  128. userPhoneMap, null, 0, null, null, goods.getBrand(), HttpUtil.getSortUrl(pushUrl + replacementInstrumentActivity.getId()));
  129. }
  130. replacementInstrumentActivity.setOpenFlag(openFlag);
  131. replacementInstrumentActivity.setUpdateTime(new Date());
  132. replacementInstrumentActivityService.update(replacementInstrumentActivity);
  133. return succeed(replacementInstrumentActivity);
  134. }
  135. @ApiOperation(value = "导出")
  136. @RequestMapping("/export")
  137. @PreAuthorize("@pcs.hasPermissions('replacementInstrumentActivity/export')")
  138. public void export(ReplacementInstrumentActivityQueryInfo queryInfo, HttpServletResponse response) throws Exception {
  139. queryInfo.setOrganId(organizationService.getEmployeeOrgan(queryInfo.getOrganId()));
  140. queryInfo.setRows(99999);
  141. PageInfo<ReplacementInstrumentActivityStatDto> pageList = replacementInstrumentActivityService.getPageList(queryInfo);
  142. if (pageList.getTotal() <= 0) {
  143. throw new BizException("没有可导出的记录");
  144. }
  145. for (ReplacementInstrumentActivityStatDto row : pageList.getRows()) {
  146. if(row.getInstrumentsId() == null){
  147. row.setHasInstrumentsId("否");
  148. }else {
  149. row.setHasInstrumentsId("是");
  150. }
  151. }
  152. OutputStream outputStream = response.getOutputStream();
  153. HSSFWorkbook workbook = null;
  154. try {
  155. String[] header = {"活动编号","分部", "合作单位编号", "合作单位","问卷标题", "缴费状态", "学员编号", "学员姓名", "联系电话", "声部", "品牌", "型号", "是否置换乐器","现金支付","余额支付"};
  156. String[] body = {"replacementInstrumentCooperationId","organName", "cooperationOrganId", "cooperationOrganName","title","payStatus==NULL || payStatus==0?'未缴费':payStatus==1?'缴费中':'已缴费'", "userId", "userName", "mobileNo", "subjectName", "brand", "specification","hasInstrumentsId","actualAmount","balance"};
  157. workbook = POIUtil.exportExcel(header, body, pageList.getRows());
  158. response.setContentType("application/octet-stream");
  159. response.setHeader("Content-Disposition", "attachment;filename=replacement-" + DateUtil.getDate(new Date()) + ".xls");
  160. response.flushBuffer();
  161. outputStream = response.getOutputStream();
  162. workbook.write(outputStream);
  163. outputStream.flush();
  164. workbook.close();
  165. } catch (Exception e) {
  166. e.printStackTrace();
  167. } finally {
  168. if (outputStream != null) {
  169. try {
  170. workbook.close();
  171. outputStream.close();
  172. } catch (IOException e) {
  173. e.printStackTrace();
  174. }
  175. }
  176. }
  177. }
  178. }