TaChannelController.java 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. package com.huiju.estateagents.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.huiju.estateagents.base.BaseController;
  7. import com.huiju.estateagents.base.ResponseBean;
  8. import io.swagger.annotations.ApiOperation;
  9. import com.huiju.estateagents.common.JWTUtils;
  10. import com.huiju.estateagents.common.StringUtils;
  11. import com.huiju.estateagents.entity.TaChannel;
  12. import com.huiju.estateagents.entity.TaPerson;
  13. import com.huiju.estateagents.mapper.TaChannelMapper;
  14. import com.huiju.estateagents.service.ITaPersonService;
  15. import com.huiju.estateagents.service.TaChannelService;
  16. import io.swagger.annotations.Api;
  17. import io.swagger.annotations.ApiImplicitParam;
  18. import io.swagger.annotations.ApiImplicitParams;
  19. import org.apache.http.HttpRequest;
  20. import org.slf4j.Logger;
  21. import org.slf4j.LoggerFactory;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.web.bind.annotation.PathVariable;
  24. import org.springframework.web.bind.annotation.RequestBody;
  25. import org.springframework.web.bind.annotation.RequestMapping;
  26. import org.springframework.web.bind.annotation.RequestMethod;
  27. import org.springframework.web.bind.annotation.RequestParam;
  28. import org.springframework.web.bind.annotation.ResponseBody;
  29. import org.springframework.web.bind.annotation.RestController;
  30. import javax.servlet.http.HttpServletRequest;
  31. import java.util.HashMap;
  32. import java.util.List;
  33. /**
  34. * <p>
  35. * 前端控制器
  36. * </p>
  37. *
  38. * @author jobob
  39. * @since 2019-09-17
  40. */
  41. @RestController
  42. @RequestMapping("/api")
  43. @Api(value = "渠道管理", tags = "渠道管理")
  44. public class TaChannelController extends BaseController {
  45. private final Logger logger = LoggerFactory.getLogger(TaChannelController.class);
  46. @Autowired
  47. public TaChannelService taChannelService;
  48. @Autowired
  49. public ITaPersonService taPersonService;
  50. @Autowired
  51. public TaChannelMapper taChannelMapper;
  52. /**
  53. * 渠道管理列表
  54. * @param pageNum
  55. * @param pageSize
  56. * @return
  57. */
  58. @ApiOperation(value = "渠道管理列表", notes = "渠道管理列表")
  59. @ApiImplicitParams({
  60. @ApiImplicitParam(dataTypeClass = Integer.class, name = "pageNum", paramType = "query",value = "第几页"),
  61. @ApiImplicitParam(dataTypeClass = Integer.class, name = "pageSize", paramType = "query",value = "一页多少行"),
  62. @ApiImplicitParam(dataTypeClass = String.class, name = "channelId", paramType = "query",value = "渠道Id"),
  63. })
  64. @RequestMapping(value="/admin/channel",method= RequestMethod.GET)
  65. public ResponseBean channelList(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
  66. @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
  67. @RequestParam(value ="channelId",required = false) Integer channelId,
  68. HttpServletRequest request){
  69. ResponseBean responseBean = new ResponseBean();
  70. Integer orgId = getOrgId(request);
  71. try {
  72. //使用分页插件
  73. IPage<TaChannel> pg = new Page<>(pageNum, pageSize);
  74. IPage<TaChannel> result = taChannelMapper.pageTaChannel(pg,orgId,channelId);
  75. HashMap hashMap = new HashMap<>();
  76. hashMap.put("result",result);
  77. // 下拉列表的数据 all
  78. List<TaChannel> taChannelList = taChannelMapper.selectChannelList(orgId);
  79. hashMap.put("channelNmae",taChannelList);
  80. responseBean.addSuccess(hashMap);
  81. }catch (Exception e){
  82. e.printStackTrace();
  83. logger.error("channelList -=- {}",e.toString());
  84. responseBean.addError(e.getMessage());
  85. }
  86. return responseBean;
  87. }
  88. /**
  89. * 渠道保存
  90. * @param channel 实体对象
  91. * @return
  92. */
  93. @ApiOperation(value = "渠道保存", notes = "渠道保存")
  94. @ApiImplicitParams({
  95. @ApiImplicitParam(dataTypeClass = TaChannel.class, name = "channel", paramType = "body",value = "当前对象"),
  96. })
  97. @RequestMapping(value="/admin/channel",method= RequestMethod.POST)
  98. public ResponseBean channelAdd(@RequestBody TaChannel channel ,HttpServletRequest request){
  99. Integer orgId = getOrgId(request);
  100. ResponseBean responseBean = new ResponseBean();
  101. try {
  102. // 生成6位数的渠道码
  103. int channelCode= taChannelMapper.channelCode();
  104. channel.setChannelCode(String.valueOf(channelCode));
  105. channel.setOrgId(orgId);
  106. if (taChannelService.save(channel)){
  107. responseBean.addSuccess(channel);
  108. }else {
  109. responseBean.addError("fail");
  110. }
  111. }catch (Exception e){
  112. e.printStackTrace();
  113. logger.error("channelAdd -=- {}",e.toString());
  114. responseBean.addError(e.getMessage());
  115. }
  116. return responseBean;
  117. }
  118. /**
  119. * 根据id删除对象
  120. * @param id 实体ID
  121. */
  122. @ApiOperation(value = "根据渠道ID删除", notes = "根据渠道ID删除")
  123. @ApiImplicitParams({
  124. @ApiImplicitParam(dataTypeClass = Integer.class, name = "id", paramType = "query",value = "渠道id"),
  125. })
  126. @ResponseBody
  127. @RequestMapping(value="/channel/{id}", method= RequestMethod.DELETE)
  128. public ResponseBean channelDelete(@PathVariable Integer id){
  129. ResponseBean responseBean = new ResponseBean();
  130. try {
  131. if(taChannelService.removeById(id)){
  132. responseBean.addSuccess("success");
  133. }else {
  134. responseBean.addError("fail");
  135. }
  136. }catch (Exception e){
  137. e.printStackTrace();
  138. logger.error("channelDelete -=- {}",e.toString());
  139. responseBean.addError(e.getMessage());
  140. }
  141. return responseBean;
  142. }
  143. /**
  144. * 修改对象
  145. * @param id 实体ID
  146. * @param channel 实体对象
  147. * @return
  148. */
  149. @ApiOperation(value = "根据渠道ID修改", notes = "根据渠道ID修改")
  150. @ApiImplicitParams({
  151. @ApiImplicitParam(dataTypeClass = Integer.class, name = "id", paramType = "query",value = "渠道id"),
  152. })
  153. @RequestMapping(value="/admin/channel/{id}",method= RequestMethod.PUT)
  154. public ResponseBean channelUpdate(@PathVariable Integer id,
  155. @RequestBody TaChannel channel){
  156. ResponseBean responseBean = new ResponseBean();
  157. try {
  158. channel.setChannelId(id);
  159. if (taChannelService.updateById(channel)){
  160. responseBean.addSuccess(channel);
  161. }else {
  162. responseBean.addError("fail");
  163. }
  164. }catch (Exception e){
  165. e.printStackTrace();
  166. logger.error("channelUpdate -=- {}",e.toString());
  167. responseBean.addError(e.getMessage());
  168. }
  169. return responseBean;
  170. }
  171. /**
  172. * 根据id查询对象
  173. * @param id 实体ID
  174. */
  175. @ApiOperation(value = "根据渠道ID查询", notes = "根据渠道ID查询")
  176. @ApiImplicitParams({
  177. @ApiImplicitParam(dataTypeClass = Integer.class, name = "id", paramType = "query",value = "渠道id"),
  178. })
  179. @RequestMapping(value="/admin/channel/{id}",method= RequestMethod.GET)
  180. public ResponseBean channelGet(@PathVariable Integer id){
  181. ResponseBean responseBean = new ResponseBean();
  182. try {
  183. responseBean.addSuccess(taChannelService.getById(id));
  184. }catch (Exception e){
  185. e.printStackTrace();
  186. logger.error("channelDelete -=- {}",e.toString());
  187. responseBean.addError(e.getMessage());
  188. }
  189. return responseBean;
  190. }
  191. /**
  192. * 渠道管理下的经纪人
  193. */
  194. @ApiOperation(value = "渠道管理下的经纪人", notes = "渠道管理下的经纪人")
  195. @ApiImplicitParams({
  196. @ApiImplicitParam(dataTypeClass = String.class, name = "name", paramType = "query",value = "姓名"),
  197. @ApiImplicitParam(dataTypeClass = String.class, name = "phone", paramType = "query",value = "电话"),
  198. @ApiImplicitParam(dataTypeClass = Integer.class, name = "channelId", paramType = "query",value = "渠道id"),
  199. @ApiImplicitParam(dataTypeClass = Integer.class, name = "pageNum", paramType = "query",value = "多少页"),
  200. @ApiImplicitParam(dataTypeClass = Integer.class, name = "pageSize", paramType = "query",value = "每页多少条"),
  201. })
  202. @RequestMapping(value="/admin/channel/broker",method= RequestMethod.GET)
  203. public ResponseBean channelBrokerList(@RequestParam(value="name",required = false) String name,
  204. @RequestParam(value="phone",required = false) String phone,
  205. @RequestParam(value="channelId",required = false) Integer channelId,
  206. @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
  207. @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
  208. HttpServletRequest request){
  209. Integer orgid = getOrgId(request);
  210. ResponseBean taPerson = taPersonService.channelBrokerList(name,phone,pageNum,pageSize,orgid,channelId);
  211. return taPerson;
  212. }
  213. /**
  214. * 渠道邀请经纪人列表
  215. */
  216. @ApiOperation(value = "渠道邀请经纪人列表", notes = "渠道邀请经纪人列表")
  217. @ApiImplicitParams({
  218. @ApiImplicitParam(dataTypeClass = String.class, name = "id", paramType = "query",value = "姓名"),
  219. @ApiImplicitParam(dataTypeClass = String.class, name = "phone", paramType = "query",value = "电话"),
  220. @ApiImplicitParam(dataTypeClass = Integer.class, name = "channelId", paramType = "query",value = "渠道id"),
  221. @ApiImplicitParam(dataTypeClass = Integer.class, name = "pageNum", paramType = "query",value = "多少页"),
  222. @ApiImplicitParam(dataTypeClass = Integer.class, name = "pageSize", paramType = "query",value = "每页多少条"),
  223. })
  224. @RequestMapping(value="/admin/channel/InviteClientsList",method= RequestMethod.GET)
  225. public ResponseBean InviteClientsList(@RequestParam(value="id",required = false) String id,
  226. @RequestParam(value="phone",required = false) String phone,
  227. @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
  228. @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
  229. HttpServletRequest request){
  230. ResponseBean taPerson = taPersonService.InviteClientsList(id,phone,pageNum,pageSize);
  231. return taPerson;
  232. }
  233. }