StoreController.java 3.16 KB
package vion.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import vion.Global;
import vion.dto.StatusDTO;
import vion.dto.StoreDTO;
import vion.model.Store;
import vion.service.IStoreService;
import vion.vo.StoreVO;
import vion.vo.UserVO;

import java.util.List;

@RestController
@RequestMapping(Global.BASE_URL)
@RequiredArgsConstructor
@Slf4j
public class StoreController {

    private final IStoreService storeService;
    private final Converter converter;


    @GetMapping("/stores")
    @SaCheckPermission(value = "store:list", orRole = "admin")
    public Page<StoreVO> getStoreList(StoreDTO data) {
        return storeService.getStoreList(data);
    }

    @GetMapping("/store")
    @SaCheckPermission(value = "store:query", orRole = "admin")
    public StoreVO getStoreById(@RequestParam Long id) {
        Store store = storeService.getById(id);
        return converter.convert(store, StoreVO.class);
    }

    @GetMapping("/storeList")
    @SaCheckPermission(value = "store:list1", orRole = "admin")
    public List<StoreVO> getStoreList(Long accountId, String name, Integer limit) {
        List<Store> storeList = storeService.lambdaQuery()
                .eq(ObjUtil.isNotNull(accountId), Store::getAccountId, accountId)
                .like(StrUtil.isNotBlank(name), Store::getName, name)
                .last(limit != null, "limit " + limit)
                .list();
        return converter.convert(storeList, StoreVO.class);
    }

    @PostMapping("/stores")
    @SaCheckPermission(value = "store:editAndSave", orRole = "admin")
    public String saveOrUpdate(@RequestBody StoreDTO data, @RequestHeader String token) {
        UserVO user = Global.USERNAME_MAP.get(token);
        // 创建项目时,默认维保状态为 --
        data.setMaintainStatus("--");
        Store store = converter.convert(data, Store.class);
        if (data.getId() != null) {
            store.setModifyUser(user.getId());
        } else {
            store.setCreateUser(user.getId());
        }
        return storeService.saveOrUpdate(store) ? "成功" : "失败";
    }

    @PostMapping("/updateStoreStatus")
    @SaCheckPermission(value = "store:editStatus", orRole = "admin")
    public Object updateStoreStage(@RequestBody StatusDTO statusDTO, @RequestHeader String token) {
        return storeService.updateStoreStage(statusDTO, token);
    }

    @PostMapping("/store/bindContract")
    @SaCheckPermission(value = "store:bindContract", orRole = "admin")
    public String setMasterContract(@RequestBody StoreDTO dto) {
        return storeService.updateById(converter.convert(dto, new Store())) ? "绑定主合同成功" : "绑定主合同失败";
    }

    @GetMapping("/store/manualCal")
    @SaCheckPermission(value = "store:calMaintainStatus", orRole = "admin")
    // todo 权限未加
    public String manualCalMaintainStatus() {
        return storeService.calMaintainStatus();
    }
}