#
vincentlu
8 天以前 efabc6ba991acfd01d38bb0bf4e8cfd772416617
zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/StaController.java
@@ -4,16 +4,20 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zy.acs.framework.common.Cools;
import com.zy.acs.framework.common.R;
import com.zy.acs.manager.common.utils.ExcelUtil;
import com.zy.acs.framework.exception.CoolException;
import com.zy.acs.manager.common.annotation.OperationLog;
import com.zy.acs.manager.common.domain.BaseParam;
import com.zy.acs.manager.common.domain.KeyValVo;
import com.zy.acs.manager.common.domain.PageParam;
import com.zy.acs.manager.common.utils.ExcelUtil;
import com.zy.acs.manager.manager.entity.Sta;
import com.zy.acs.manager.manager.entity.StaReserve;
import com.zy.acs.manager.manager.service.StaReserveService;
import com.zy.acs.manager.manager.service.StaService;
import com.zy.acs.manager.system.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
@@ -25,6 +29,8 @@
    @Autowired
    private StaService staService;
    @Autowired
    private StaReserveService staReserveService;
    @PreAuthorize("hasAuthority('manager:sta:list')")
    @PostMapping("/sta/page")
@@ -56,10 +62,16 @@
    @OperationLog("Create Sta")
    @PostMapping("/sta/save")
    public R save(@RequestBody Sta sta) {
        sta.setCreateBy(getLoginUserId());
        sta.setCreateTime(new Date());
        sta.setUpdateBy(getLoginUserId());
        sta.setUpdateTime(new Date());
        if (staService.count(new LambdaQueryWrapper<Sta>()
                .eq(Sta::getStaNo, sta.getStaNo())) > 0) {
            return R.error("sta No. has already exist !");
        }
        Long loginUserId = getLoginUserId();
        Date now = new Date();
        sta.setCreateBy(loginUserId);
        sta.setCreateTime(now);
        sta.setUpdateBy(loginUserId);
        sta.setUpdateTime(now);
        if (!staService.save(sta)) {
            return R.error("Save Fail");
        }
@@ -70,6 +82,15 @@
    @OperationLog("Update Sta")
    @PostMapping("/sta/update")
    public R update(@RequestBody Sta sta) {
        // 唯一性校验:只有当 sta No. 非空时才校验(避免空值误判)
        if (!Cools.isEmpty(sta.getStaNo())) {
            boolean exists = staService.count(new LambdaQueryWrapper<Sta>()
                    .eq(Sta::getStaNo, sta.getStaNo())
                    .ne(Sta::getId, sta.getId())) > 0;
            if (exists) {
                throw new CoolException("failed to update, because sta No. has already exist !");
            }
        }
        sta.setUpdateBy(getLoginUserId());
        sta.setUpdateTime(new Date());
        if (!staService.updateById(sta)) {
@@ -81,9 +102,13 @@
    @PreAuthorize("hasAuthority('manager:sta:remove')")
    @OperationLog("Delete Sta")
    @PostMapping("/sta/remove/{ids}")
    @Transactional
    public R remove(@PathVariable Long[] ids) {
        if (!staService.removeByIds(Arrays.asList(ids))) {
            return R.error("Delete Fail");
        for (Long id : ids) {
            staReserveService.remove(new LambdaQueryWrapper<StaReserve>().eq(StaReserve::getStaId, id));
            if (!staService.removeById(id)) {
                throw new CoolException("remove Fail");
            }
        }
        return R.ok("Delete Success").add(ids);
    }