BackendStaffController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. package com.fuint.module.backendApi.controller;
  2. import com.fuint.common.Constants;
  3. import com.fuint.common.dto.AccountInfo;
  4. import com.fuint.common.dto.ParamDto;
  5. import com.fuint.common.enums.StaffCategoryEnum;
  6. import com.fuint.common.enums.StatusEnum;
  7. import com.fuint.common.service.StaffService;
  8. import com.fuint.common.util.CommonUtil;
  9. import com.fuint.common.util.PhoneFormatCheckUtils;
  10. import com.fuint.common.util.TokenUtil;
  11. import com.fuint.framework.exception.BusinessCheckException;
  12. import com.fuint.framework.pagination.PaginationRequest;
  13. import com.fuint.framework.pagination.PaginationResponse;
  14. import com.fuint.framework.web.BaseController;
  15. import com.fuint.framework.web.ResponseObject;
  16. import com.fuint.repository.model.MtStaff;
  17. import com.fuint.utils.StringUtil;
  18. import io.swagger.annotations.Api;
  19. import io.swagger.annotations.ApiOperation;
  20. import lombok.AllArgsConstructor;
  21. import org.springframework.security.access.prepost.PreAuthorize;
  22. import org.springframework.web.bind.annotation.*;
  23. import javax.servlet.http.HttpServletRequest;
  24. import java.util.ArrayList;
  25. import java.util.HashMap;
  26. import java.util.List;
  27. import java.util.Map;
  28. /**
  29. * 店铺员工管理
  30. *
  31. * Created by FSQ
  32. * CopyRight https://www.fuint.cn
  33. */
  34. @Api(tags="管理端-店铺员工相关接口")
  35. @RestController
  36. @AllArgsConstructor
  37. @RequestMapping(value = "/backendApi/staff")
  38. public class BackendStaffController extends BaseController {
  39. /**
  40. * 员工接口
  41. */
  42. private StaffService staffService;
  43. /**
  44. * 获取员工列表
  45. *
  46. * @param request HttpServletRequest对象
  47. * @return 员工列表页面
  48. */
  49. @ApiOperation(value = "获取员工列表")
  50. @RequestMapping(value = "/list", method = RequestMethod.GET)
  51. @CrossOrigin
  52. @PreAuthorize("@pms.hasPermission('staff:list')")
  53. public ResponseObject list(HttpServletRequest request) throws BusinessCheckException {
  54. String token = request.getHeader("Access-Token");
  55. Integer page = request.getParameter("page") == null ? Constants.PAGE_NUMBER : Integer.parseInt(request.getParameter("page"));
  56. Integer pageSize = request.getParameter("pageSize") == null ? Constants.PAGE_SIZE : Integer.parseInt(request.getParameter("pageSize"));
  57. String mobile = request.getParameter("mobile");
  58. String realName = request.getParameter("realName");
  59. String auditedStatus = request.getParameter("status");
  60. String storeId = request.getParameter("storeId");
  61. String category = request.getParameter("category");
  62. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  63. if (accountInfo == null) {
  64. return getFailureResult(1001, "请先登录");
  65. }
  66. if (accountInfo.getStoreId() != null && accountInfo.getStoreId() > 0) {
  67. storeId = accountInfo.getStoreId().toString();
  68. }
  69. PaginationRequest paginationRequest = new PaginationRequest();
  70. paginationRequest.setCurrentPage(page);
  71. paginationRequest.setPageSize(pageSize);
  72. Map<String, Object> params = new HashMap<>();
  73. if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
  74. params.put("merchantId", accountInfo.getMerchantId());
  75. }
  76. if (StringUtil.isNotEmpty(realName)) {
  77. params.put("name", realName);
  78. }
  79. if (StringUtil.isNotEmpty(mobile)) {
  80. params.put("mobile", mobile);
  81. }
  82. if (StringUtil.isNotEmpty(auditedStatus)) {
  83. params.put("status", auditedStatus);
  84. }
  85. if (StringUtil.isNotEmpty(storeId)) {
  86. params.put("storeId", storeId);
  87. }
  88. if (StringUtil.isNotEmpty(category)) {
  89. params.put("category", category);
  90. }
  91. paginationRequest.setSearchParams(params);
  92. PaginationResponse<MtStaff> paginationResponse = staffService.queryStaffListByPagination(paginationRequest);
  93. // 员工类别列表
  94. StaffCategoryEnum[] categoryListEnum = StaffCategoryEnum.values();
  95. List<ParamDto> categoryList = new ArrayList<>();
  96. for (StaffCategoryEnum enumItem : categoryListEnum) {
  97. ParamDto paramDto = new ParamDto();
  98. paramDto.setKey(enumItem.getKey());
  99. paramDto.setName(enumItem.getName());
  100. paramDto.setValue(enumItem.getKey());
  101. categoryList.add(paramDto);
  102. }
  103. Map<String, Object> result = new HashMap<>();
  104. result.put("paginationResponse", paginationResponse);
  105. result.put("categoryList", categoryList);
  106. return getSuccessResult(result);
  107. }
  108. /**
  109. * 更新员工状态
  110. * @return
  111. */
  112. @ApiOperation(value = "更新员工状态")
  113. @RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
  114. @CrossOrigin
  115. @PreAuthorize("@pms.hasPermission('staff:list')")
  116. public ResponseObject updateStatus(HttpServletRequest request, @RequestBody Map<String, Object> params) throws BusinessCheckException {
  117. String token = request.getHeader("Access-Token");
  118. String status = params.get("status") != null ? params.get("status").toString() : StatusEnum.ENABLED.getKey();
  119. Integer id = params.get("id") == null ? 0 : Integer.parseInt(params.get("id").toString());
  120. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  121. if (accountInfo == null) {
  122. return getFailureResult(1001, "请先登录");
  123. }
  124. staffService.updateAuditedStatus(id, status);
  125. return getSuccessResult(true);
  126. }
  127. /**
  128. * 保存员工信息
  129. *
  130. * @param request
  131. * @return
  132. */
  133. @ApiOperation(value = "保存员工信息")
  134. @RequestMapping(value = "/save", method = RequestMethod.POST)
  135. @CrossOrigin
  136. @PreAuthorize("@pms.hasPermission('staff:list')")
  137. public ResponseObject saveHandler(HttpServletRequest request, @RequestBody Map<String, Object> params) throws BusinessCheckException {
  138. String token = request.getHeader("Access-Token");
  139. String id = params.get("id") == null ? "0" : params.get("id").toString();
  140. String storeId = params.get("storeId") == null ? "0" : params.get("storeId").toString();
  141. String category = params.get("category") == null ? "0" : params.get("category").toString();
  142. String mobile = params.get("mobile") == null ? "" : CommonUtil.replaceXSS(params.get("mobile").toString());
  143. String realName = params.get("realName") == null ? "" : CommonUtil.replaceXSS(params.get("realName").toString());
  144. String description = params.get("description") == null ? "" : CommonUtil.replaceXSS(params.get("description").toString());
  145. String status = params.get("auditedStatus") == null ? StatusEnum.FORBIDDEN.getKey() : CommonUtil.replaceXSS(params.get("auditedStatus").toString());
  146. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  147. if (accountInfo == null) {
  148. return getFailureResult(1001, "请先登录");
  149. }
  150. MtStaff mtStaff = new MtStaff();
  151. if (StringUtil.isNotEmpty(id)) {
  152. mtStaff = staffService.queryStaffById(Integer.parseInt(id));
  153. }
  154. if (mtStaff == null && StringUtil.isNotEmpty(id)) {
  155. return getFailureResult(201, "员工信息不存在");
  156. }
  157. mtStaff.setMerchantId(accountInfo.getMerchantId());
  158. mtStaff.setStoreId(Integer.parseInt(storeId));
  159. mtStaff.setRealName(realName);
  160. if (PhoneFormatCheckUtils.isChinaPhoneLegal(mobile)) {
  161. mtStaff.setMobile(mobile);
  162. }
  163. mtStaff.setAuditedStatus(status);
  164. mtStaff.setDescription(description);
  165. mtStaff.setCategory(Integer.parseInt(category));
  166. if (StringUtil.isEmpty(mtStaff.getMobile())) {
  167. return getFailureResult(201, "手机号码不能为空");
  168. } else {
  169. MtStaff tempUser = staffService.queryStaffByMobile(mtStaff.getMobile());
  170. if (tempUser != null && !tempUser.getId().equals(mtStaff.getId())) {
  171. return getFailureResult(201, "该手机号码已经存在");
  172. }
  173. }
  174. staffService.saveStaff(mtStaff);
  175. return getSuccessResult(true);
  176. }
  177. /**
  178. * 查询员工详情
  179. *
  180. * @param id
  181. * @return
  182. */
  183. @ApiOperation(value = "查询员工详情")
  184. @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
  185. @CrossOrigin
  186. @PreAuthorize("@pms.hasPermission('staff:list')")
  187. public ResponseObject getStaffInfo(HttpServletRequest request, @PathVariable("id") Integer id) throws BusinessCheckException {
  188. String token = request.getHeader("Access-Token");
  189. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  190. if (accountInfo == null) {
  191. return getFailureResult(1001, "请先登录");
  192. }
  193. MtStaff staffInfo = staffService.queryStaffById(id);
  194. if (staffInfo != null) {
  195. // 隐藏手机号中间四位
  196. String phone = staffInfo.getMobile();
  197. if (phone != null && StringUtil.isNotEmpty(phone) && phone.length() == 11) {
  198. staffInfo.setMobile(phone.substring(0, 3) + "****" + phone.substring(7));
  199. }
  200. }
  201. Map<String, Object> result = new HashMap<>();
  202. result.put("staffInfo", staffInfo);
  203. return getSuccessResult(result);
  204. }
  205. /**
  206. * 店铺员工列表
  207. *
  208. * @param storeId
  209. * @return
  210. */
  211. @ApiOperation(value = "店铺员工列表")
  212. @RequestMapping(value = "/storeStaffList/{storeId}", method = RequestMethod.GET)
  213. @CrossOrigin
  214. public ResponseObject storeStaffList(HttpServletRequest request, @PathVariable("storeId") Integer storeId) throws BusinessCheckException {
  215. String token = request.getHeader("Access-Token");
  216. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  217. if (accountInfo == null) {
  218. return getFailureResult(1001, "请先登录");
  219. }
  220. Map<String, Object> params = new HashMap<>();
  221. params.put("AUDITED_STATUS", StatusEnum.ENABLED.getKey());
  222. params.put("STORE_ID", storeId);
  223. List<MtStaff> staffList = staffService.queryStaffByParams(params);
  224. Map<String, Object> result = new HashMap<>();
  225. result.put("staffList", staffList);
  226. return getSuccessResult(result);
  227. }
  228. /**
  229. * 删除员工
  230. *
  231. * @param id
  232. * @return
  233. */
  234. @ApiOperation(value = "删除员工")
  235. @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
  236. @CrossOrigin
  237. @PreAuthorize("@pms.hasPermission('staff:list')")
  238. public ResponseObject deleteStaff(HttpServletRequest request, @PathVariable("id") Integer id) throws BusinessCheckException {
  239. String token = request.getHeader("Access-Token");
  240. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  241. if (accountInfo == null) {
  242. return getFailureResult(1001, "请先登录");
  243. }
  244. staffService.updateAuditedStatus(id, StatusEnum.DISABLE.getKey());
  245. return getSuccessResult(true);
  246. }
  247. }