| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.system.domain.TShop; |
| | | import com.ruoyi.system.dto.TShopDTO; |
| | | import com.ruoyi.system.query.TShopQuery; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.ruoyi.system.service.TShopService; |
| | | import com.ruoyi.system.vo.TShopVO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @author xiaochen |
| | | * @since 2024-08-14 |
| | | */ |
| | | @Api(tags = "店铺信息") |
| | | @RestController |
| | | @RequestMapping("/t-shop") |
| | | public class TShopController { |
| | | |
| | | private final TShopService shopService; |
| | | private final ISysUserService userService; |
| | | |
| | | @Autowired |
| | | public TShopController(TShopService shopService, ISysUserService userService) { |
| | | this.shopService = shopService; |
| | | this.userService = userService; |
| | | } |
| | | |
| | | /** |
| | | * 查询店铺信息分页列表 |
| | | */ |
| | | @ApiOperation( value = "查询店铺信息分页列表") |
| | | @PostMapping(value = "/pageList") |
| | | public AjaxResult<PageInfo<TShopVO>> pageList(@RequestBody TShopQuery query) { |
| | | return AjaxResult.success(shopService.pageList(query)); |
| | | } |
| | | |
| | | /** |
| | | * 添加店铺信息 |
| | | */ |
| | | @ApiOperation( value = "添加店铺信息") |
| | | @PostMapping(value = "/add") |
| | | public AjaxResult<String> add(@RequestBody TShopDTO dto) { |
| | | shopService.save(dto); |
| | | // 添加账号 |
| | | userService.addAccount(dto); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * 编辑店铺信息 |
| | | */ |
| | | @ApiOperation( value = "编辑店铺信息") |
| | | @PostMapping(value = "/edit") |
| | | public AjaxResult<String> edit(@RequestBody TShopDTO dto) { |
| | | shopService.updateById(dto); |
| | | userService.updateAccount(dto); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * 查看店铺信息详情 |
| | | */ |
| | | @ApiOperation( value = "查看店铺信息详情") |
| | | @GetMapping(value = "/getDetailById") |
| | | public AjaxResult<TShop> getDetailById(@RequestParam("id") Long id) { |
| | | return AjaxResult.success(shopService.getById(id)); |
| | | } |
| | | |
| | | /** |
| | | * 删除店铺信息 |
| | | */ |
| | | @ApiOperation( value = "删除店铺信息") |
| | | @DeleteMapping(value = "/deleteById") |
| | | public AjaxResult<Boolean> deleteById(@RequestParam("id") Long id) { |
| | | TShop shop = shopService.getById(id); |
| | | // 查询账号 |
| | | SysUser sysUser = userService.selectUserByUserName(shop.getAccount()); |
| | | if(Objects.nonNull(sysUser)){ |
| | | userService.deleteUserById(sysUser.getUserId()); |
| | | } |
| | | return AjaxResult.success(shopService.removeById(id)); |
| | | } |
| | | |
| | | /** |
| | | * 启用禁用店铺 |
| | | */ |
| | | @ApiOperation( value = "启用禁用店铺") |
| | | @GetMapping(value = "/updateStatus") |
| | | public AjaxResult<Boolean> updateStatus(@RequestParam(value = "id") Integer id, |
| | | @RequestParam(value = "status") Integer status) { |
| | | TShop shop = shopService.getById(id); |
| | | shop.setStatus(status); |
| | | shopService.updateById(shop); |
| | | SysUser sysUser = userService.selectUserByUserName(shop.getAccount()); |
| | | if(Objects.nonNull(sysUser)){ |
| | | if(status == 1){ |
| | | sysUser.setStatus("0"); |
| | | }else { |
| | | sysUser.setStatus("1"); |
| | | } |
| | | userService.updateUser(sysUser); |
| | | } |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | } |
| | | |