| New file |
| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | |
| | | import cn.hutool.core.util.RandomUtil; |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.model.TCompany; |
| | | import com.ruoyi.system.model.TPhysicalGoods; |
| | | import com.ruoyi.system.query.BigGiftPackageQuery; |
| | | import com.ruoyi.system.query.CompanyUserQuery; |
| | | import com.ruoyi.system.query.TCompanyQuery; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.ruoyi.system.service.TCompanyService; |
| | | import com.ruoyi.system.service.TPhysicalGoodsService; |
| | | import com.ruoyi.web.controller.system.SysUserController; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.client.RestTemplate; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * <p> |
| | | * 公司 前端控制器 |
| | | * </p> |
| | | * |
| | | * @author xiaochen |
| | | * @since 2025-12-08 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/t-company") |
| | | @Api(tags = "(嘉视达)公司 管理") |
| | | public class TCompanyController extends BaseController { |
| | | |
| | | |
| | | private final TCompanyService companyService; |
| | | private final ISysUserService userService; |
| | | private final RedisTemplate redisTemplate; |
| | | |
| | | |
| | | public TCompanyController(TCompanyService companyService, ISysUserService userService, RedisTemplate redisTemplate) { |
| | | this.companyService = companyService; |
| | | this.userService = userService; |
| | | this.redisTemplate = redisTemplate; |
| | | } |
| | | |
| | | @ApiOperation(value = "公司分页列表") |
| | | @PostMapping(value = "/pageList") |
| | | public R<Page<TCompany>> pageList(@RequestBody TCompanyQuery query) { |
| | | Page<TCompany> page = new Page<>(query.getPageNum(), query.getPageSize()); |
| | | LambdaQueryWrapper<TCompany> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.ne(TCompany::getStatus, 3); |
| | | wrapper.like(Objects.nonNull(query.getName()), TCompany::getName, query.getName()); |
| | | wrapper.like(Objects.nonNull(query.getChargePerson()), TCompany::getChargePerson, query.getChargePerson()); |
| | | wrapper.orderByDesc(TCompany::getCreateTime); |
| | | Page<TCompany> pageInfo = companyService.page(page, wrapper); |
| | | return R.ok(pageInfo); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "公司详情") |
| | | @PostMapping(value = "/detail/{id}") |
| | | public R<TCompany> detail(@PathVariable Integer id) { |
| | | TCompany company = companyService.getById(id); |
| | | return R.ok(company); |
| | | } |
| | | |
| | | @ApiOperation(value = "公司添加") |
| | | @PostMapping(value = "/add") |
| | | @Log(title = "添加公司-添加", businessType = BusinessType.INSERT) |
| | | public R<String> add(@RequestBody TCompany company) { |
| | | company.setStatus(1); |
| | | company.setCreateUserId(getUserId()); |
| | | SysUser user = new SysUser(); |
| | | user.setRoleType(2); |
| | | user.setDeptId(124l); |
| | | user.setIsAdmin(1); |
| | | user.setUserName(company.getAccount()); |
| | | user.setPassword(company.getPassword()); |
| | | user.setPhonenumber(company.getChargePersonPhone()); |
| | | user.setNickName(company.getChargePerson()); |
| | | user.setRoleId(1l); |
| | | if (!userService.checkUserNameUnique(user)) { |
| | | return R.fail("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); |
| | | } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { |
| | | return R.fail("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); |
| | | } |
| | | user.setCreateBy(getUsername()); |
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
| | | int count = userService.insertUser(user); |
| | | if (count > 0) { |
| | | boolean save = companyService.save(company); |
| | | if (save) { |
| | | user.setCompanyId(company.getId()); |
| | | userService.updateUser(user); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "公司修改") |
| | | @PostMapping(value = "/edit") |
| | | @Log(title = "修改公司-修改", businessType = BusinessType.UPDATE) |
| | | public R<String> edit(@RequestBody TCompany company) { |
| | | SysUser user = userService.getUserByCompanyId(company.getId()); |
| | | if (!userService.checkUserNameUnique(user)) { |
| | | return R.fail("修改用户'" + user.getUserName() + "'失败,登录账号已存在"); |
| | | } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { |
| | | return R.fail("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); |
| | | } |
| | | user.setUserName(company.getAccount()); |
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
| | | company.setUpdateUserId(getUserId()); |
| | | int count = userService.updateUser(user); |
| | | if (count > 0) { |
| | | boolean update = companyService.updateById(company); |
| | | return R.ok(); |
| | | } |
| | | return R.fail(); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "公司删除") |
| | | @DeleteMapping(value = "/delete/{id}") |
| | | @Log(title = "删除公司-删除", businessType = BusinessType.DELETE) |
| | | public R<String> delete(@PathVariable Integer id) { |
| | | TCompany tCompany = companyService.getById(id); |
| | | tCompany.setStatus(3); |
| | | companyService.updateById(tCompany); |
| | | |
| | | SysUser userByCompanyId = userService.getUserByCompanyId(tCompany.getId()); |
| | | userByCompanyId.setDelFlag("2"); |
| | | userService.deleteUserByIds(Arrays.asList(userByCompanyId.getUserId())); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | |
| | | @ApiOperation(value = "公司需求--管理人员列表") |
| | | @PostMapping(value = "/getCompanyUserList") |
| | | public R<Page<SysUser>> getCompanyUserList(@RequestBody CompanyUserQuery query) { |
| | | Page<SysUser> page = new Page<>(query.getPageNum(), query.getPageSize()); |
| | | List<SysUser> list = userService.getCompanyUserList(page,query.getCompanyId()); |
| | | page.setRecords(list); |
| | | return R.ok(page); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "公司需求--管理人员获取二维码") |
| | | @GetMapping(value = "/getQrcode") |
| | | public R<String> getQrcode(@RequestParam Long userId) { |
| | | Object o = redisTemplate.opsForValue().get("ADMIN_WX_IMG" + userId); |
| | | if(o!=null){ |
| | | return R.ok(o.toString()); |
| | | } |
| | | String accessToken = getAccessToken(); |
| | | String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken; |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("page", "pages/home/home"); |
| | | param.put("width", 430); //二维码尺寸 |
| | | param.put("scene", "userId=" + userId); //二维码尺寸 |
| | | param.put("env_version", "trial"); //二维码尺寸 |
| | | HttpRequest post = HttpUtil.createPost(url); |
| | | post.body(JSON.toJSONString(param)); |
| | | |
| | | byte[] result = post.execute().bodyBytes(); |
| | | // base64 |
| | | String img = Base64.getEncoder().encodeToString(result); |
| | | // 后台用户的小程序码 |
| | | redisTemplate.opsForValue().set("ADMIN_WX_IMG" + userId, img); |
| | | return R.ok(img); |
| | | } |
| | | |
| | | |
| | | @Value("${wx.url}") |
| | | private String ACCESS_TOKEN_URL; |
| | | |
| | | @Value("${wx.conf.secretId}") |
| | | private String memberAppSecret; |
| | | |
| | | @Value("${wx.conf.appId}") |
| | | private String wxAppId; |
| | | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | |
| | | public String getAccessToken() { |
| | | Object o = redisTemplate.opsForValue().get("accessToken"); |
| | | if(o!=null){ |
| | | return o.toString(); |
| | | } |
| | | String requestUrl = MessageFormat.format(ACCESS_TOKEN_URL,wxAppId,memberAppSecret); |
| | | String respBody = restTemplate.getForEntity(requestUrl, String.class).getBody(); |
| | | JSONObject jsonObject = JSONObject.parseObject(respBody); |
| | | String string = jsonObject.getString("access_token"); |
| | | redisTemplate.opsForValue().set("accessToken", string,5000, TimeUnit.SECONDS); |
| | | return string; |
| | | } |
| | | |
| | | @ApiOperation(value = "新增股东管理",response = SysUser.class) |
| | | @Log(title = "公司信息-新增股东", businessType = BusinessType.INSERT) |
| | | @PostMapping("/system/user/add") |
| | | public R<String> add(@RequestBody SysUser user) |
| | | { |
| | | user.setUserName(user.getUserName()); |
| | | if (!userService.checkUserNameUnique(user)) |
| | | { |
| | | return R.fail("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); |
| | | } |
| | | else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) |
| | | { |
| | | return R.fail("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); |
| | | } |
| | | user.setCreateBy(getUsername()); |
| | | user.setPassword(SecurityUtils.encryptPassword("123456")); |
| | | // 随机10数数字 |
| | | user.setCode(RandomUtil.randomNumbers(10)); |
| | | userService.insertUser(user); |
| | | if(user.getCompanyId()!=null){ |
| | | String accessToken = getAccessToken(); |
| | | String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken; |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("page", "pages/home/home"); |
| | | param.put("width", 430); //二维码尺寸 |
| | | param.put("scene", "userId=" + user.getUserId()); //二维码尺寸 |
| | | param.put("env_version", "trial"); //二维码尺寸 |
| | | HttpRequest post = HttpUtil.createPost(url); |
| | | post.body(JSON.toJSONString(param)); |
| | | |
| | | byte[] result = post.execute().bodyBytes(); |
| | | // base64 |
| | | String img = Base64.getEncoder().encodeToString(result); |
| | | // 后台用户的小程序码 |
| | | redisTemplate.opsForValue().set("ADMIN_WX_IMG" + user.getUserId(), img); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation(value = "修改股东管理") |
| | | @Log(title = "公司信息-修改股东", businessType = BusinessType.UPDATE) |
| | | @PostMapping("/system/user/edit") |
| | | public R edit(@RequestBody SysUser user) |
| | | { |
| | | user.setUserName(user.getPhonenumber()); |
| | | // userService.checkUserAllowed(user); |
| | | // userService.checkUserDataScope(user.getUserId()); |
| | | if (!userService.checkUserNameUnique(user)) |
| | | { |
| | | return R.fail("修改用户'" + user.getUserName() + "'失败,登录账号已存在"); |
| | | } |
| | | else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) |
| | | { |
| | | return R.fail("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); |
| | | } |
| | | |
| | | user.setUpdateBy(getUsername()); |
| | | if(StringUtils.isNotEmpty(user.getPassword())){ |
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
| | | } |
| | | return R.ok(userService.updateUser(user)); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "批量删除股东") |
| | | @Log(title = "公司信息-批量删除股东", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/system/user/deleteById/{ids}") |
| | | public AjaxResult remove(@PathVariable String ids) |
| | | { |
| | | String[] split = ids.split(","); |
| | | List<Long> userIds = new ArrayList<>(); |
| | | for (String s : split) { |
| | | userIds.add(Long.valueOf(s)); |
| | | } |
| | | if (userIds.contains(getUserId())) |
| | | { |
| | | return error("当前用户不能删除"); |
| | | } |
| | | return AjaxResult.success(userService.deleteUserByIds(userIds)); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |