| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- package cn.com.goldenwater.dcproj.controller.base;
- import cn.com.goldenwater.dcproj.model.AttInspType;
- import cn.com.goldenwater.dcproj.param.AttInspTypeParam;
- import cn.com.goldenwater.dcproj.service.AttInspTypeService;
- import cn.com.goldenwater.core.web.BaseController;
- import cn.com.goldenwater.core.web.BaseResponse;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import io.swagger.annotations.ApiParam;
- import org.apache.commons.lang3.StringUtils;
- import com.github.pagehelper.PageInfo;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.List;
- /**
- * @author lune
- * @date 2019-7-19
- */
- @Api(value = "ATT 督查对象类型管理", tags = "ATT 督查对象类型管理")
- @RestController
- @RequestMapping("/att/insp/type")
- public class AttInspTypeController extends BaseController {
- private Logger logger = LoggerFactory.getLogger(getClass());
- @Autowired
- private AttInspTypeService attInspTypeService;
- @ApiOperation(value = "添加/修改督查对象类型")
- @RequestMapping(value = "", method = RequestMethod.POST)
- public BaseResponse<AttInspType> insert(@ApiParam(name = "attInspType", value = "AttInspType", required = true) @RequestBody AttInspType attInspType) {
- if (StringUtils.isBlank(attInspType.getCode())) {
- int codeMax = attInspTypeService.getMaxCode();
- codeMax++;
- String code = String.valueOf(codeMax);
- if (String.valueOf(code).length() == 1) {
- code = "00" + code;
- }
- if (String.valueOf(code).length() == 2) {
- code = "0" + code;
- }
- attInspType.setCode(code);
- attInspTypeService.insert(attInspType);
- } else {
- attInspTypeService.update(attInspType);
- }
- return buildSuccessResponse(attInspType);
- }
- @ApiOperation(value = "根据ID删除督查对象类型")
- @RequestMapping(value = "/del/{id}", method = RequestMethod.GET)
- public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
- int ret = attInspTypeService.delete(id);
- return buildSuccessResponse();
- }
- @ApiOperation(value = "根据ID获取督查对象类型(单表)")
- @RequestMapping(value = "/{id}", method = RequestMethod.GET)
- public BaseResponse<AttInspType> get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
- AttInspType attInspType = attInspTypeService.get(id);
- return buildSuccessResponse(attInspType);
- }
- @ApiOperation(value = "获取督查对象类型(列表所有)")
- @RequestMapping(value = "/list", method = RequestMethod.POST)
- public BaseResponse<List<AttInspType>> list(@ApiParam(name = "attInspTypeParam", value = "attInspTypeParam", required = true) @RequestBody AttInspTypeParam attInspTypeParam) {
- List<AttInspType> attInspTypeList = attInspTypeService.findList(attInspTypeParam);
- Collections.sort(attInspTypeList, new Comparator<AttInspType>() {
- @Override
- public int compare(AttInspType o1, AttInspType o2) {
- return Integer.valueOf(o1.getCode()) - Integer.valueOf(o2.getCode());
- }
- });
- return buildSuccessResponse(attInspTypeList);
- }
- @ApiOperation(value = "获取督查对象类型(列表--分页)")
- @RequestMapping(value = "/page", method = RequestMethod.POST)
- public BaseResponse<PageInfo<AttInspType>> page(@ApiParam(name = "attInspTypeParam", value = "attInspTypeParam", required = true) @RequestBody AttInspTypeParam attInspTypeParam) {
- PageInfo<AttInspType> attInspTypeList = attInspTypeService.findPageInfo(attInspTypeParam);
- return buildSuccessResponse(attInspTypeList);
- }
- @ApiOperation(value = "获取督查对象类型(列表所有,code去0)")
- @RequestMapping(value = "/getTypes", method = RequestMethod.POST)
- public BaseResponse<List<AttInspType>> getTypes(@ApiParam(name = "attInspTypeParam", value = "attInspTypeParam", required = true) @RequestBody AttInspTypeParam attInspTypeParam) {
- List<AttInspType> attInspTypeList = attInspTypeService.findList(attInspTypeParam);
- attInspTypeList.forEach(attInspType -> attInspType.setCode(String.valueOf(Integer.valueOf(attInspType.getCode()))));
- Collections.sort(attInspTypeList, new Comparator<AttInspType>() {
- @Override
- public int compare(AttInspType o1, AttInspType o2) {
- return Integer.valueOf(o1.getCode()) - Integer.valueOf(o2.getCode());
- }
- });
- return buildSuccessResponse(attInspTypeList);
- }
- }
|