TaPointsExchangeController.java 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. package com.huiju.estateagents.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.huiju.estateagents.base.BaseController;
  6. import com.huiju.estateagents.base.ResponseBean;
  7. import com.huiju.estateagents.common.CommConstant;
  8. import com.huiju.estateagents.common.DateUtils;
  9. import com.huiju.estateagents.common.ExcelUtils;
  10. import com.huiju.estateagents.entity.TaGoods;
  11. import com.huiju.estateagents.entity.TaPointsExchange;
  12. import com.huiju.estateagents.excel.TaPointsExchangeExport;
  13. import com.huiju.estateagents.service.ITaGoodsService;
  14. import com.huiju.estateagents.service.ITaPointsExchangeService;
  15. import io.swagger.annotations.Api;
  16. import io.swagger.annotations.ApiImplicitParam;
  17. import io.swagger.annotations.ApiImplicitParams;
  18. import io.swagger.annotations.ApiOperation;
  19. import org.slf4j.Logger;
  20. import org.slf4j.LoggerFactory;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.web.bind.annotation.PathVariable;
  23. import org.springframework.web.bind.annotation.RequestBody;
  24. import org.springframework.web.bind.annotation.RequestMapping;
  25. import org.springframework.web.bind.annotation.RequestMethod;
  26. import org.springframework.web.bind.annotation.RequestParam;
  27. import org.springframework.web.bind.annotation.ResponseBody;
  28. import org.springframework.web.bind.annotation.RestController;
  29. import javax.servlet.http.HttpServletRequest;
  30. import javax.servlet.http.HttpServletResponse;
  31. import java.time.LocalDateTime;
  32. import java.util.ArrayList;
  33. import java.util.List;
  34. /**
  35. * <p>
  36. * 积分兑换记录 前端控制器
  37. * </p>
  38. *
  39. * @author jobob
  40. * @since 2019-07-25
  41. */
  42. @RestController
  43. @RequestMapping("/api")
  44. @Api(value = "积分兑换", tags = "积分兑换")
  45. public class TaPointsExchangeController extends BaseController {
  46. private final Logger logger = LoggerFactory.getLogger(TaPointsExchangeController.class);
  47. @Autowired
  48. public ITaPointsExchangeService iTaPointsExchangeService;
  49. @Autowired
  50. private ITaGoodsService taGoodsService;
  51. /**
  52. * 分页查询列表
  53. * @param pageNum
  54. * @param pageSize
  55. * @return
  56. */
  57. @RequestMapping(value="/admin/taPointsExchange",method= RequestMethod.GET)
  58. public ResponseBean taPointsExchangeList(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
  59. @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
  60. @RequestParam(value ="personName",required = false) String personName,
  61. @RequestParam(value ="phone",required = false) String phone,
  62. @RequestParam(value ="personType",required = false) String personType,
  63. @RequestParam(value ="targetName",required = false) String targetName,
  64. @RequestParam(value ="startCreateDate",required = false) String startCreateDate,
  65. @RequestParam(value ="endCreateDate",required = false) String endCreateDate,
  66. @RequestParam(value ="startVerifyDate",required = false) String startVerifyDate,
  67. @RequestParam(value ="endVerifyDate",required = false) String endVerifyDate,
  68. @RequestParam(value ="status",required = false) Integer status,
  69. @RequestParam(value ="tel",required = false) String tel, HttpServletRequest request){
  70. ResponseBean responseBean = new ResponseBean();
  71. try {
  72. //使用分页插件
  73. TaPointsExchange taPointsExchange = new TaPointsExchange();
  74. taPointsExchange.setPersonName(personName);
  75. taPointsExchange.setPhone(phone);
  76. taPointsExchange.setPersonType(personType);
  77. taPointsExchange.setTargetName(targetName);
  78. taPointsExchange.setStartCreateDate(startCreateDate);
  79. taPointsExchange.setEndCreateDate(endCreateDate);
  80. taPointsExchange.setStartVerifyDate(startVerifyDate);
  81. taPointsExchange.setEndVerifyDate(endVerifyDate);
  82. taPointsExchange.setStatus(status);
  83. taPointsExchange.setTel(tel);
  84. taPointsExchange.setOrgId(getOrgId(request));
  85. responseBean = iTaPointsExchangeService.selectList(pageNum,pageSize,taPointsExchange,getTaPersonBuildingListByUserId(request));
  86. }catch (Exception e){
  87. e.printStackTrace();
  88. logger.error("taPointsExchangeList -=- {}",e.toString());
  89. responseBean.addError(e.getMessage());
  90. }
  91. return responseBean;
  92. }
  93. /**
  94. * 分页查询列表
  95. * @param pageNum
  96. * @param pageSize
  97. * @return
  98. */
  99. @RequestMapping(value="/admin/taPointsExchange/export",method= RequestMethod.GET)
  100. public ResponseBean taPointsExchangeExport(@RequestParam(value ="personName",required = false) String personName,
  101. @RequestParam(value ="phone",required = false) String phone,
  102. @RequestParam(value ="personType",required = false) String personType,
  103. @RequestParam(value ="targetName",required = false) String targetName,
  104. @RequestParam(value ="startCreateDate",required = false) String startCreateDate,
  105. @RequestParam(value ="endCreateDate",required = false) String endCreateDate,
  106. @RequestParam(value ="startVerifyDate",required = false) String startVerifyDate,
  107. @RequestParam(value ="endVerifyDate",required = false) String endVerifyDate,
  108. @RequestParam(value ="status",required = false) Integer status,
  109. @RequestParam(value ="tel",required = false) String tel,
  110. HttpServletRequest request,
  111. HttpServletResponse response){
  112. ResponseBean responseBean = new ResponseBean();
  113. try {
  114. //使用分页插件
  115. TaPointsExchange taPointsExchange = new TaPointsExchange();
  116. taPointsExchange.setPersonName(personName);
  117. taPointsExchange.setPhone(phone);
  118. taPointsExchange.setPersonType(personType);
  119. taPointsExchange.setTargetName(targetName);
  120. taPointsExchange.setStartCreateDate(startCreateDate);
  121. taPointsExchange.setEndCreateDate(endCreateDate);
  122. taPointsExchange.setStartVerifyDate(startVerifyDate);
  123. taPointsExchange.setEndVerifyDate(endVerifyDate);
  124. taPointsExchange.setStatus(status);
  125. taPointsExchange.setTel(tel);
  126. taPointsExchange.setOrgId(getOrgId(request));
  127. responseBean = iTaPointsExchangeService.selectList(1, 9999,taPointsExchange,getTaPersonBuildingListByUserId(request));
  128. List<TaPointsExchange> records = ((Page<TaPointsExchange>) responseBean.getData()).getRecords();
  129. List<TaPointsExchangeExport> list = new ArrayList<>();
  130. if (null != records) {
  131. for (TaPointsExchange item: records) {
  132. TaPointsExchangeExport row = new TaPointsExchangeExport();
  133. row.setPersonName(item.getPersonName());
  134. row.setPhone(item.getPhone());
  135. row.setPersonType("prop".equals(item.getPersonType()) ? "物业相关" : ("life-consultant".equals(item.getPersonType()) ? "生活管家" : null));
  136. row.setTargetName(item.getTargetName());
  137. row.setStatus(1 == item.getStatus() ? "已领取" : "未领取");
  138. row.setCreateDate(DateUtils.format(item.getCreateDate(), "yyyy-MM-dd HH:mm"));
  139. row.setVerifyDate(DateUtils.format(item.getVerifyDate(), "yyyy-MM-dd HH:mm"));
  140. list.add(row);
  141. }
  142. }
  143. ExcelUtils.flush(response, TaPointsExchangeExport.class, list, "积分兑换记录" + DateUtils.today());
  144. }catch (Exception e){
  145. e.printStackTrace();
  146. logger.error("taPointsExchangeList -=- {}",e.toString());
  147. responseBean.addError(e.getMessage());
  148. }
  149. return responseBean;
  150. }
  151. /**
  152. * 修改对象
  153. * @param taPointsExchange 实体对象
  154. * @return
  155. */
  156. @RequestMapping(value="/admin/taPointsExchange/change",method= RequestMethod.PUT)
  157. public ResponseBean taPointsExchangeStatusChange(@RequestBody TaPointsExchange taPointsExchange){
  158. ResponseBean responseBean = new ResponseBean();
  159. try {
  160. if (null != taPointsExchange.getStatus() && !taPointsExchange.getStatus().equals(CommConstant.STATUS_NORMAL)){
  161. taPointsExchange.setVerifyDate(LocalDateTime.now());
  162. taPointsExchange.setStatus(CommConstant.STATUS_NORMAL);
  163. }
  164. if (iTaPointsExchangeService.updateById(taPointsExchange)){
  165. responseBean.addSuccess(taPointsExchange);
  166. }else {
  167. responseBean.addError("fail");
  168. }
  169. }catch (Exception e){
  170. e.printStackTrace();
  171. logger.error("taPointsExchangeUpdate -=- {}",e.toString());
  172. responseBean.addError(e.getMessage());
  173. }
  174. return responseBean;
  175. }
  176. /**
  177. * 保存对象
  178. * @param taPointsExchange 实体对象
  179. * @return
  180. */
  181. @RequestMapping(value="/taPointsExchange",method= RequestMethod.POST)
  182. public ResponseBean taPointsExchangeAdd(@RequestBody TaPointsExchange taPointsExchange){
  183. ResponseBean responseBean = new ResponseBean();
  184. try {
  185. if (iTaPointsExchangeService.save(taPointsExchange)){
  186. responseBean.addSuccess(taPointsExchange);
  187. }else {
  188. responseBean.addError("fail");
  189. }
  190. }catch (Exception e){
  191. e.printStackTrace();
  192. logger.error("taPointsExchangeAdd -=- {}",e.toString());
  193. responseBean.addError(e.getMessage());
  194. }
  195. return responseBean;
  196. }
  197. /**
  198. * 根据id删除对象
  199. * @param id 实体ID
  200. */
  201. @ResponseBody
  202. @RequestMapping(value="/taPointsExchange/{id}", method= RequestMethod.DELETE)
  203. public ResponseBean taPointsExchangeDelete(@PathVariable Integer id){
  204. ResponseBean responseBean = new ResponseBean();
  205. try {
  206. if(iTaPointsExchangeService.removeById(id)){
  207. responseBean.addSuccess("success");
  208. }else {
  209. responseBean.addError("fail");
  210. }
  211. }catch (Exception e){
  212. e.printStackTrace();
  213. logger.error("taPointsExchangeDelete -=- {}",e.toString());
  214. responseBean.addError(e.getMessage());
  215. }
  216. return responseBean;
  217. }
  218. /**
  219. * 修改对象
  220. * @param recId 实体ID
  221. * @return
  222. */
  223. @RequestMapping(value="/admin/taPointsExchange/{recId}",method= RequestMethod.PUT)
  224. public ResponseBean taPointsExchangeUpdate(@PathVariable Integer recId){
  225. ResponseBean responseBean = new ResponseBean();
  226. try {
  227. TaPointsExchange taPointsExchange = iTaPointsExchangeService.getById(recId);
  228. if (null == taPointsExchange){
  229. responseBean.addError("找不到需要核销的商品");
  230. return responseBean;
  231. }
  232. if (taPointsExchange.getStatus().equals(CommConstant.STATUS_NORMAL)){
  233. responseBean.addError("此商品已经被领取");
  234. return responseBean;
  235. }
  236. taPointsExchange.setStatus(CommConstant.STATUS_NORMAL);
  237. taPointsExchange.setVerifyDate(LocalDateTime.now());
  238. if (iTaPointsExchangeService.updateById(taPointsExchange)){
  239. responseBean.addSuccess(taPointsExchange);
  240. }else {
  241. responseBean.addError("fail");
  242. }
  243. }catch (Exception e){
  244. e.printStackTrace();
  245. logger.error("taPointsExchangeUpdate -=- {}",e.toString());
  246. responseBean.addError(e.getMessage());
  247. }
  248. return responseBean;
  249. }
  250. /**
  251. * 根据id查询对象
  252. * @param id 实体ID
  253. */
  254. @RequestMapping(value="/taPointsExchange/{id}",method= RequestMethod.GET)
  255. public ResponseBean taPointsExchangeGet(@PathVariable Integer id){
  256. ResponseBean responseBean = new ResponseBean();
  257. try {
  258. responseBean.addSuccess(iTaPointsExchangeService.getById(id));
  259. }catch (Exception e){
  260. e.printStackTrace();
  261. logger.error("taPointsExchangeDelete -=- {}",e.toString());
  262. responseBean.addError(e.getMessage());
  263. }
  264. return responseBean;
  265. }
  266. /**
  267. * 分页查询列表
  268. * @param pageNumber
  269. * @param pageSize
  270. * @return
  271. */
  272. @ApiOperation(value = "微信积分兑换列表", notes = "微信积分兑换列表")
  273. @ApiImplicitParams({
  274. @ApiImplicitParam(dataTypeClass = Integer.class, name = "pageNumber", paramType = "query",value = "第几页"),
  275. @ApiImplicitParam(dataTypeClass = Integer.class, name = "pageSize", paramType = "query",value = "一页多少行"),
  276. @ApiImplicitParam(dataTypeClass = Integer.class, name = "personId", paramType = "query",value = "当前人员personId"),
  277. })
  278. @RequestMapping(value="/wx/taPointsExchange",method= RequestMethod.GET)
  279. public ResponseBean wxPointsExchangeList(@RequestParam(value ="pageNumber",defaultValue = "1") Integer pageNumber,
  280. @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
  281. @RequestParam(value = "buildingId", required = false) String buildingId,
  282. @RequestParam(value = "personId", required = false) String personId,
  283. HttpServletRequest request){
  284. if (null == personId) {
  285. personId = getPersonId(request);
  286. }
  287. ResponseBean responseBean = new ResponseBean();
  288. try {
  289. //使用分页插件
  290. IPage<TaPointsExchange> pg = new Page<>(pageNumber, pageSize);
  291. QueryWrapper<TaPointsExchange> queryWrapper = new QueryWrapper<>();
  292. queryWrapper.eq(null != personId, "person_id", personId);
  293. queryWrapper.eq(null != buildingId, "building_id",buildingId);
  294. queryWrapper.orderByDesc("create_date");
  295. IPage<TaPointsExchange> result = iTaPointsExchangeService.page(pg, queryWrapper);
  296. List<TaPointsExchange> records = result.getRecords();
  297. records.forEach(e -> {
  298. if (null == e.getStatus() || e.getStatus().equals(CommConstant.STATUS_UNACCALIMED)){
  299. TaGoods goods = taGoodsService.getById(e.getTargetId());
  300. e.setAddress(goods.getAddress());
  301. }
  302. });
  303. result.setRecords(records);
  304. responseBean.addSuccess(result);
  305. }catch (Exception e){
  306. e.printStackTrace();
  307. logger.error("taPointsExchangeList -=- {}",e.toString());
  308. responseBean.addError(e.getMessage());
  309. }
  310. return responseBean;
  311. }
  312. }