|
@@ -0,0 +1,115 @@
|
|
|
|
+package com.hb.proj.base.controller;
|
|
|
|
+
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+
|
|
|
|
+import com.hb.proj.allconfig.AccessToken;
|
|
|
|
+import com.hb.proj.allconfig.SysLog;
|
|
|
|
+import com.hb.proj.base.service.UnitService;
|
|
|
|
+import com.hb.proj.model.UnitPO;
|
|
|
|
+import com.hb.proj.utils.RequestParams;
|
|
|
|
+import com.hb.proj.utils.RespVO;
|
|
|
|
+import com.hb.proj.utils.RespVOBuilder;
|
|
|
|
+import com.hb.xframework.dao.util.PageModel;
|
|
|
|
+
|
|
|
|
+import jakarta.validation.constraints.NotBlank;
|
|
|
|
+
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/base/unit")
|
|
|
|
+@Validated
|
|
|
|
+public class UnitController {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private UnitService service;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 加载所有单位
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping("/loadAll")
|
|
|
|
+ public RespVO<List<UnitPO>> loadAll(){
|
|
|
|
+ PageModel<UnitPO> pages=service.query(null,1,10000);
|
|
|
|
+ return RespVOBuilder.ok(pages!=null?pages.getData():null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询单位列表
|
|
|
|
+ * @apiNote 查询参数类型列表
|
|
|
|
+ * @param params 查询参数
|
|
|
|
+ * @param pageNum 页码
|
|
|
|
+ * @param pageSize 每页记录数
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping("/query")
|
|
|
|
+ public RespVO<PageModel<UnitPO>> query(RequestParams params,
|
|
|
|
+ @RequestParam(value = "currentPage", defaultValue = "1") Integer pageNum,
|
|
|
|
+ @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize) {
|
|
|
|
+ return RespVOBuilder.ok(service.query(params.getObjectMap(), pageNum, pageSize));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获得单个单位数据
|
|
|
|
+ * @param unitId 单位记录id
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping("/get")
|
|
|
|
+ public RespVO<UnitPO> get(@NotBlank(message = "缺少记录号") String unitId){
|
|
|
|
+ return RespVOBuilder.ok(service.get(unitId));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 删除单个单位数据
|
|
|
|
+ * @param unitId 待删除记录id
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping("/delete")
|
|
|
|
+ @SysLog("删除单位信息:{arg0}")
|
|
|
|
+ public RespVO<Object> delete(String unitId){
|
|
|
|
+ service.delete(unitId);
|
|
|
|
+ return RespVOBuilder.ok();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 增加新单位
|
|
|
|
+ * @param device 设备实体对象
|
|
|
|
+ * @param token 当前登录实体
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping("/add")
|
|
|
|
+ public RespVO<String> add(UnitPO unit,AccessToken token){
|
|
|
|
+ if(service.exist(unit.getUnitSymbol(),null)) {
|
|
|
|
+ return RespVOBuilder.error("该单位已存在,勿重复添加");
|
|
|
|
+ }
|
|
|
|
+ unit.setModifyBy(token.getUsName());
|
|
|
|
+ return RespVOBuilder.ok(service.add(unit));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 更新单位信息
|
|
|
|
+ * @param device 单位实体对象
|
|
|
|
+ * @param token 当前登录实体
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping("/update")
|
|
|
|
+ public RespVO<Object> update(UnitPO unit,AccessToken token){
|
|
|
|
+ if(service.exist(unit.getUnitSymbol(),unit.getUnitId())) {
|
|
|
|
+ return RespVOBuilder.error("该单位已存在,勿重复添加");
|
|
|
|
+ }
|
|
|
|
+ unit.setModifyBy(token.getUsName());
|
|
|
|
+ service.update(unit);
|
|
|
|
+
|
|
|
|
+ return RespVOBuilder.ok();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|