| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- package com.ym.mec.web.controller;
- import com.beust.jcommander.internal.Lists;
- import com.ym.mec.auth.api.client.SysUserFeignService;
- import com.ym.mec.biz.dal.dao.ReplacementInstrumentActivityDao;
- import com.ym.mec.biz.dal.dao.SysConfigDao;
- import com.ym.mec.biz.dal.dto.ReplacementInstrumentActivityStatDto;
- import com.ym.mec.biz.dal.entity.Goods;
- import com.ym.mec.biz.dal.entity.ReplacementInstrumentActivity;
- import com.ym.mec.biz.dal.entity.ReplacementInstrumentCooperation;
- import com.ym.mec.biz.dal.enums.MessageTypeEnum;
- import com.ym.mec.biz.dal.enums.YesOrNoEnum;
- import com.ym.mec.biz.dal.page.ReplacementInstrumentActivityQueryInfo;
- import com.ym.mec.biz.service.*;
- import com.ym.mec.common.controller.BaseController;
- import com.ym.mec.common.entity.HttpResponseResult;
- import com.ym.mec.common.exception.BizException;
- import com.ym.mec.common.page.PageInfo;
- import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
- import com.ym.mec.util.date.DateUtil;
- import com.ym.mec.util.excel.POIUtil;
- import com.ym.mec.util.http.HttpUtil;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import org.apache.poi.hssf.usermodel.HSSFWorkbook;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.security.access.prepost.PreAuthorize;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Map;
- @RequestMapping("${app-config.url.web:}/replacementInstrumentActivity")
- @Api(tags = "乐器置换-调查问卷服务")
- @RestController
- public class ReplacementInstrumentActivityController extends BaseController {
- @Autowired
- private ReplacementInstrumentActivityService replacementInstrumentActivityService;
- @Autowired
- private OrganizationService organizationService;
- @Autowired
- private ReplacementInstrumentActivityDao replacementInstrumentActivityDao;
- @Autowired
- private ReplacementInstrumentCooperationService replacementInstrumentCooperationService;
- @Autowired
- private SysConfigDao sysConfigDao;
- @Autowired
- private SysMessageService sysMessageService;
- @Autowired
- private GoodsService goodsService;
- @ApiOperation(value = "分页查询列表")
- @GetMapping("/queryPage")
- @PreAuthorize("@pcs.hasPermissions('replacementInstrumentActivity/queryPage')")
- public HttpResponseResult<PageInfo<ReplacementInstrumentActivityStatDto>> queryPage(ReplacementInstrumentActivityQueryInfo queryInfo) {
- queryInfo.setOrganId(organizationService.getEmployeeOrgan(queryInfo.getOrganId()));
- return succeed(replacementInstrumentActivityService.getPageList(queryInfo));
- }
- @ApiOperation(value = "统计信息查询")
- @GetMapping("/queryReplacementsStat")
- public HttpResponseResult<PageInfo<ReplacementInstrumentActivityStatDto>> queryReplacementsStat(ReplacementInstrumentActivityQueryInfo queryInfo) {
- return succeed(replacementInstrumentActivityService.queryReplacementsStat(queryInfo));
- }
- @ApiOperation(value = "统计信息查询")
- @GetMapping("/resultSync")
- public void resultSync() {
- replacementInstrumentActivityService.resultSync();
- }
- @ApiOperation(value = "修改")
- @PostMapping("/update")
- @PreAuthorize("@pcs.hasPermissions('replacementInstrumentActivity/update')")
- public HttpResponseResult<ReplacementInstrumentActivity> update(ReplacementInstrumentActivity replacementInstrumentActivity) {
- replacementInstrumentActivity.setGoodsId(replacementInstrumentActivity.getInstrumentsId());
- ReplacementInstrumentActivity oldReplacementInstrumentActivity = replacementInstrumentActivityDao.getLock(replacementInstrumentActivity.getId());
- if (!oldReplacementInstrumentActivity.getPayStatus().equals(0)) {
- return failed("支付中、已支付的乐器置换,不能修改");
- }
- ReplacementInstrumentCooperation byCooperationId = replacementInstrumentCooperationService.get(oldReplacementInstrumentActivity.getReplacementInstrumentCooperationId());
- if (byCooperationId.getOpenPay().equals(YesOrNoEnum.YES) && oldReplacementInstrumentActivity.getInstrumentsId() == null && replacementInstrumentActivity.getInstrumentsId() != null) {
- Goods goods = goodsService.get(replacementInstrumentActivity.getInstrumentsId());
- goods.setBrand(goodsService.getBrandMap().getOrDefault(goods.getBrand(),goods.getBrand()));
- Map<Integer, String> userMap = new HashMap<>();
- Map<Integer, String> userPhoneMap = new HashMap<>();
- Integer userId = oldReplacementInstrumentActivity.getUserId();
- String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
- String pushUrl = baseApiUrl + "/#/questionGoodsSale?id=";
- userMap.put(userId, userId.toString());
- sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.STUDENT_SMS_PUSH_REPLACEMENT_PAY,
- userMap, null, 0, "5?" + pushUrl + replacementInstrumentActivity.getId(), "STUDENT", goods.getBrand(), "");
- userPhoneMap.put(userId, oldReplacementInstrumentActivity.getMobileNo());
- sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS, MessageTypeEnum.STUDENT_SMS_PUSH_REPLACEMENT_PAY,
- userPhoneMap, null, 0, null, null, goods.getBrand(), HttpUtil.getSortUrl(pushUrl + replacementInstrumentActivity.getId()));
- }
- oldReplacementInstrumentActivity.setSubjectId(replacementInstrumentActivity.getSubjectId());
- oldReplacementInstrumentActivity.setInstrumentsId(replacementInstrumentActivity.getInstrumentsId());
- oldReplacementInstrumentActivity.setGoodsId(replacementInstrumentActivity.getInstrumentsId());
- oldReplacementInstrumentActivity.setUpdateTime(new Date());
- replacementInstrumentActivityService.update(oldReplacementInstrumentActivity);
- return succeed(replacementInstrumentActivity);
- }
- @ApiOperation(value = "开启/关闭缴费")
- @PostMapping("/updateOpenFlag")
- @PreAuthorize("@pcs.hasPermissions('replacementInstrumentActivity/updateOpenFlag')")
- public HttpResponseResult<ReplacementInstrumentActivity> updateOpenFlag(Integer Id,Integer openFlag) {
- ReplacementInstrumentActivity replacementInstrumentActivity = replacementInstrumentActivityDao.getLock(Id);
- if (!replacementInstrumentActivity.getPayStatus().equals(0)) {
- return failed("支付中、已支付的乐器置换,不能修改");
- }
- if(replacementInstrumentActivity.getInstrumentsId() == null){
- return failed("修改失败:用户没有可置换商品");
- }
- if (openFlag == 1) {
- Goods goods = goodsService.get(replacementInstrumentActivity.getInstrumentsId());
- goods.setBrand(goodsService.getBrandMap().getOrDefault(goods.getBrand(),goods.getBrand()));
- Map<Integer, String> userMap = new HashMap<>();
- Map<Integer, String> userPhoneMap = new HashMap<>();
- Integer userId = replacementInstrumentActivity.getUserId();
- String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
- String pushUrl = baseApiUrl + "/#/questionGoodsSale?id=";
- userMap.put(userId, userId.toString());
- sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.STUDENT_SMS_PUSH_REPLACEMENT_PAY,
- userMap, null, 0, "5?" + pushUrl + replacementInstrumentActivity.getId(), "STUDENT", goods.getBrand(), "");
- userPhoneMap.put(userId, replacementInstrumentActivity.getMobileNo());
- sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS, MessageTypeEnum.STUDENT_SMS_PUSH_REPLACEMENT_PAY,
- userPhoneMap, null, 0, null, null, goods.getBrand(), HttpUtil.getSortUrl(pushUrl + replacementInstrumentActivity.getId()));
- }
- replacementInstrumentActivity.setOpenFlag(openFlag);
- replacementInstrumentActivity.setUpdateTime(new Date());
- replacementInstrumentActivityService.update(replacementInstrumentActivity);
- return succeed(replacementInstrumentActivity);
- }
- @ApiOperation(value = "导出")
- @RequestMapping("/export")
- @PreAuthorize("@pcs.hasPermissions('replacementInstrumentActivity/export')")
- public void export(ReplacementInstrumentActivityQueryInfo queryInfo, HttpServletResponse response) throws Exception {
- queryInfo.setOrganId(organizationService.getEmployeeOrgan(queryInfo.getOrganId()));
- queryInfo.setRows(99999);
- PageInfo<ReplacementInstrumentActivityStatDto> pageList = replacementInstrumentActivityService.getPageList(queryInfo);
- if (pageList.getTotal() <= 0) {
- throw new BizException("没有可导出的记录");
- }
- for (ReplacementInstrumentActivityStatDto row : pageList.getRows()) {
- if(row.getInstrumentsId() == null){
- row.setHasInstrumentsId("否");
- }else {
- row.setHasInstrumentsId("是");
- }
- }
- OutputStream outputStream = response.getOutputStream();
- HSSFWorkbook workbook = null;
- try {
- String[] header = {"活动编号","分部", "合作单位编号", "合作单位","问卷标题", "缴费状态", "学员编号", "学员姓名", "联系电话", "声部", "品牌", "型号", "是否置换乐器","现金支付","余额支付"};
- String[] body = {"replacementInstrumentCooperationId","organName", "cooperationOrganId", "cooperationOrganName","title","payStatus==NULL || payStatus==0?'未缴费':payStatus==1?'缴费中':'已缴费'", "userId", "userName", "mobileNo", "subjectName", "brand", "specification","hasInstrumentsId","actualAmount","balance"};
- workbook = POIUtil.exportExcel(header, body, pageList.getRows());
- response.setContentType("application/octet-stream");
- response.setHeader("Content-Disposition", "attachment;filename=replacement-" + DateUtil.getDate(new Date()) + ".xls");
- response.flushBuffer();
- outputStream = response.getOutputStream();
- workbook.write(outputStream);
- outputStream.flush();
- workbook.close();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (outputStream != null) {
- try {
- workbook.close();
- outputStream.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
|