package com.ics.admin.controller; import cn.hutool.core.lang.Assert; import com.ics.admin.service.IIcsCustomerStaffService; import com.ics.common.constant.Constants; import com.ics.common.core.controller.BaseController; import com.ics.common.core.domain.IcsCustomerStaff; import com.ics.common.core.domain.R; import com.ics.system.domain.User; import com.ics.system.service.IUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.wf.jwtp.annotation.Ignore; import org.wf.jwtp.annotation.RequiresPermissions; import java.util.Date; import java.util.List; /** * 企业员工 提供者 * * @author ics * @date 2024-02-19 */ @RestController @RequestMapping("/admin/staff") public class CustomerStaffController extends BaseController { private final static String ACCESS_USERID = Constants.ACCESS_USERID; @Autowired private IIcsCustomerStaffService icsCustomerStaffService; @Autowired private IUserService userService; /** * 查询企业员工 */ @GetMapping("get/{id}") public IcsCustomerStaff get(@PathVariable("id") Long id) { return icsCustomerStaffService.selectIcsCustomerStaffById(id); } /** * 查询企业员工列表 */ @RequiresPermissions("admin:staff:list") @GetMapping("list") public R list(IcsCustomerStaff icsCustomerStaff) { startPage(); String customerId = icsCustomerStaff.getCustomerId(); if (customerId != null && !"".equals(customerId)) { icsCustomerStaff.setIcsCustomerId(Long.valueOf(customerId)); } // Integer customerId = getLoginCustomerId(); // icsCustomerStaff.setIcsCustomerId(customerId.longValue()); // icsCustomerStaff.setDataType(Constants.CUSTOMER_STAFF); return result(icsCustomerStaffService.selectIcsCustomerStaffList(icsCustomerStaff)); } @Ignore @GetMapping("getStaffListNotId") public R getStaffListNotId(IcsCustomerStaff icsCustomerStaff) { startPage(); String customerId = icsCustomerStaff.getCustomerId(); if (customerId != null && !"".equals(customerId)) { icsCustomerStaff.setIcsCustomerId(Long.valueOf(customerId)); } // Integer customerId = getLoginCustomerId(); // icsCustomerStaff.setIcsCustomerId(customerId.longValue()); // icsCustomerStaff.setDataType(Constants.CUSTOMER_STAFF); return result(icsCustomerStaffService.getStaffListNotId(icsCustomerStaff)); } @Ignore @GetMapping("getStaffListByUser") public R getStaffListByUser(IcsCustomerStaff icsCustomerStaff) { startPage(); String customerId = icsCustomerStaff.getCustomerId(); if (customerId != null && !"".equals(customerId)) { icsCustomerStaff.setIcsCustomerId(Long.valueOf(customerId)); } List staffListByUser = icsCustomerStaffService.getStaffListByUser(icsCustomerStaff); if (icsCustomerStaff.getStaffId() != null){ IcsCustomerStaff customerStaff = icsCustomerStaffService.selectIcsCustomerStaffById(icsCustomerStaff.getStaffId()); if (null != customerStaff){ staffListByUser.add(customerStaff); } } return result(staffListByUser); } /** * 新增保存企业员工 */ @RequiresPermissions("admin:staff:add") @PostMapping("save") public R addSave(@RequestBody IcsCustomerStaff icsCustomerStaff) { Long customerId = getLoginCustomerId(); icsCustomerStaff.setIcsCustomerId(customerId); icsCustomerStaff.setCreateTime(new Date()); icsCustomerStaff.setCreateBy(getLoginName()); icsCustomerStaff.setDataType(Constants.CUSTOMER_STAFF); User user = userService.selectUserByMobile(icsCustomerStaff.getMobile()); int i = icsCustomerStaffService.insertIcsCustomerStaff(icsCustomerStaff); if(i>0){ user.setStaffId(icsCustomerStaff.getId()); userService.updateUser(user); } return toAjax(i); } /** * 修改保存企业员工 */ @Ignore @PostMapping("update") public R editSave(@RequestBody IcsCustomerStaff icsCustomerStaff) { IcsCustomerStaff customerStaff = icsCustomerStaffService.selectIcsCustomerStaffById(icsCustomerStaff.getId()); Assert.isTrue(null !=customerStaff , "用户不存在,请联系管理员"); customerStaff.setIcsCustomerId(Long.valueOf(icsCustomerStaff.getCustomerId())); icsCustomerStaff.setUpdateTime(new Date()); // icsCustomerStaff.setUpdateBy(getLoginName()); return toAjax(icsCustomerStaffService.updateIcsCustomerStaff(customerStaff)); } /** * 删除企业员工 */ @RequiresPermissions("admin:staff:remove") @PostMapping("remove") public R remove(String ids) { return toAjax(icsCustomerStaffService.deleteIcsCustomerStaffByIds(ids)); } }