|
@@ -0,0 +1,106 @@
|
|
|
+package com.management.platform.controller;
|
|
|
+
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.management.platform.entity.Project;
|
|
|
+import com.management.platform.entity.ProjectBasecost;
|
|
|
+import com.management.platform.entity.ProjectCategory;
|
|
|
+import com.management.platform.entity.ProjectCategory;
|
|
|
+import com.management.platform.mapper.*;
|
|
|
+import com.management.platform.util.HttpRespMsg;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 前端控制器
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author Seyason
|
|
|
+ * @since 2022-03-24
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/project-category")
|
|
|
+public class ProjectCategoryController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private HttpServletRequest request;
|
|
|
+ @Resource
|
|
|
+ UserMapper userMapper;
|
|
|
+ @Resource
|
|
|
+ ProjectCategoryMapper projectCategoryMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ ProjectMapper projectMapper;
|
|
|
+
|
|
|
+ @RequestMapping("/addOrMod")
|
|
|
+ public HttpRespMsg addOrMod(ProjectCategory setting) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ if (StringUtils.isEmpty(setting.getName())) {
|
|
|
+ msg.setError("名称不能为空");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("TOKEN")).getCompanyId();
|
|
|
+ if (setting.getId() == null) {
|
|
|
+ setting.setCompanyId(companyId);
|
|
|
+ int count = projectCategoryMapper.selectCount(new QueryWrapper<ProjectCategory>().eq("name", setting.getName()).eq("company_id", setting.getCompanyId()));
|
|
|
+ if (count > 0) {
|
|
|
+ msg.setError("该名称已存在");
|
|
|
+ } else {
|
|
|
+ projectCategoryMapper.insert(setting);
|
|
|
+ msg.data = projectCategoryMapper.selectList(new QueryWrapper<ProjectCategory>().eq("company_id", companyId));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ int count = projectCategoryMapper.selectCount(new QueryWrapper<ProjectCategory>().eq("name", setting.getName())
|
|
|
+ .eq("company_id", companyId).ne("id", setting.getId()));
|
|
|
+ if (count > 0) {
|
|
|
+ msg.setError("该名称已存在");
|
|
|
+ } else {
|
|
|
+ //检查名称是否有变化
|
|
|
+ ProjectCategory oldSetting = projectCategoryMapper.selectById(setting.getId());
|
|
|
+ if (!setting.getName().equals(oldSetting.getName())) {
|
|
|
+ projectCategoryMapper.updateById(setting);
|
|
|
+ Project cost = new Project();
|
|
|
+ cost.setCategoryName(setting.getName());
|
|
|
+ projectMapper.update(cost, new QueryWrapper<Project>().eq("category", setting.getId()));
|
|
|
+ }
|
|
|
+ msg.data = projectCategoryMapper.selectList(new QueryWrapper<ProjectCategory>().eq("company_id", companyId));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/list")
|
|
|
+ public HttpRespMsg list() {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("TOKEN")).getCompanyId();
|
|
|
+ List<ProjectCategory> list = projectCategoryMapper.selectList(new QueryWrapper<ProjectCategory>().eq("company_id", companyId));
|
|
|
+ msg.data = list;
|
|
|
+
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/delete")
|
|
|
+ public HttpRespMsg delete(Integer id) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ ProjectCategory ProjectCategory = projectCategoryMapper.selectById(id);
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("TOKEN")).getCompanyId();
|
|
|
+ if (!ProjectCategory.getCompanyId().equals(companyId)) {
|
|
|
+ msg.setError("无权操作");
|
|
|
+ } else {
|
|
|
+ projectCategoryMapper.deleteById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|