StoreController.java 7.73 KB
package vion.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vion.Global;
import vion.enums.ResultEnum;
import vion.model.*;
import vion.service.IAddressSerrvice;
import vion.service.IFileSerrvice;
import vion.service.IStoreSerrvice;
import vion.utils.ResultUtil;
import vion.vo.StatusVO;
import vion.vo.StoreVO;

import java.util.Date;
import java.util.List;

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

    @Autowired
    private IStoreSerrvice storeSerrvice;
    @Autowired
    private IFileSerrvice fileSerrvice;
    @Autowired
    private IAddressSerrvice addressSerrvice;

    @GetMapping("/stores")
    @ResponseBody
    public Object getStoreList(@RequestParam(name = "account_id")Integer account_id,
                               @RequestParam(name = "store_id")Integer store_id,
                               @RequestParam(name = "storenum",required=false)String storenum,
                               @RequestParam(name = "project_state",required=false)Integer project_state,
                               @RequestParam(name = "salesperson",required=false)String salesperson,
                               @RequestParam(name = "implement_type",required=false)Integer implement_type,
                               @RequestParam(name = "startdate",required=false) Date startdate,
                               @RequestParam(name = "enddate",required=false) Date enddate,
                               @RequestParam(name = "pageNum")Integer pageNum,
                               @RequestParam(name = "pageSize")Integer pageSize){

        //pageNum当前页,pageSize每页条数
        PageHelper.startPage(pageNum,pageSize);

        QueryWrapper<Store> wrapper=new QueryWrapper<>();
        wrapper.eq("store_id",store_id);
        wrapper.eq("account_id",account_id);
        if(storenum!=null)
            wrapper.eq("storenum",storenum);
        if(project_state!=null)
            wrapper.eq("project_state",project_state);
        if(salesperson!=null)
            wrapper.eq("salesperson",salesperson);
        if(implement_type!=null)
            wrapper.eq("implement_type",implement_type);
        if(startdate!=null)
            wrapper.ge("orderdate",startdate);
        if(enddate!=null)
            wrapper.le("orderdate",enddate);

        List<Store> storeList=storeSerrvice.list(wrapper);

        PageInfo pageInfo=new PageInfo(storeList,10);

        if (pageInfo != null) {
            return ResultUtil.success(pageInfo);
        } else {
            return ResultUtil.error(ResultEnum.SELECT_ERROR);
        }
    }

    @GetMapping("/store")
    @ResponseBody
    public Object getStoreByID(@RequestParam(name = "id")Integer id){

        StoreVO storeVo=new StoreVO();//storeDao.getStoreByID(store_id);

        Store store=storeSerrvice.getById(id);
        storeVo.setId(store.getId());
        storeVo.setNumber(store.getNumber());
        storeVo.setName(store.getName());
        storeVo.setStorenum(store.getStorenum());
        storeVo.setAmount(store.getAmount());
        storeVo.setOrderdate(store.getOrderdate());
        storeVo.setSalesperson(store.getSalesperson());
        storeVo.setWarranty_period(store.getWarrantyPeriod());
        storeVo.setCustomer_name(store.getCustomerName());
        storeVo.setProject_stage(store.getProjectStage());
        storeVo.setProject_state(store.getProjectState());
        storeVo.setContacts(store.getContacts());
        storeVo.setRemark(store.getRemark());
        //获取地址信息
        Address address=addressSerrvice.getOne(Wrappers.<Address>lambdaQuery()
                .eq(Address::getStoreId,id));
        if(address!=null){
            storeVo.setConsignee_name(address.getConsigneeName());
            storeVo.setConsignee_phone(address.getConsigneePhone());
            storeVo.setConsignee_address(address.getConsigneeAddress());
            storeVo.setContract_name(address.getContractName());
            storeVo.setContract_phone(address.getContractPhone());
            storeVo.setContract_address(address.getContractAddress());
            storeVo.setInvoice_name(address.getInvoiceName());
            storeVo.setInvoice_phone(address.getInvoicePhone());
            storeVo.setInvoice_address(address.getInvoiceAddress());
            storeVo.setInvoice_info(address.getInvoiceInfo());
        }

        if (storeVo != null) {
            return ResultUtil.success(storeVo);
        } else {
            return ResultUtil.error(ResultEnum.SELECT_ERROR);
        }
    }

    @PostMapping("/stores")
    @ResponseBody
    public Object saveOrUpdate(@RequestBody StoreVO storeVo) {

        Store store=new Store();
        store.setId(storeVo.getId());
        store.setNumber(storeVo.getNumber());
        store.setName(storeVo.getName());
        store.setStorenum(storeVo.getStorenum());
        store.setAmount(storeVo.getAmount());
        store.setOrderdate(storeVo.getOrderdate());
        store.setSalesperson(storeVo.getSalesperson());
        store.setWarrantyPeriod(storeVo.getWarranty_period());
        store.setCustomerName(storeVo.getCustomer_name());
        store.setProjectStage(storeVo.getProject_stage());
        store.setProjectState(storeVo.getProject_state());
        store.setContacts(storeVo.getContacts());
        store.setRemark(storeVo.getRemark());

        Address address=addressSerrvice.getOne(Wrappers.<Address>lambdaQuery()
                .eq(Address::getStoreId,storeVo.getId()));
        address.setConsigneeName(storeVo.getConsignee_name());
        address.setConsigneePhone(storeVo.getConsignee_phone());
        address.setConsigneeAddress(storeVo.getConsignee_address());
        address.setContractName(storeVo.getContract_name());
        address.setContractPhone(storeVo.getContract_phone());
        address.setContractAddress(storeVo.getContract_address());
        address.setInvoiceName(storeVo.getInvoice_name());
        address.setInvoicePhone(storeVo.getInvoice_phone());
        address.setInvoiceAddress(storeVo.getInvoice_address());
        address.setInvoiceInfo(storeVo.getInvoice_info());


        try {
            storeSerrvice.saveOrUpdate(store);
            addressSerrvice.saveOrUpdate(address);

            return ResultUtil.success();
        }catch (Exception e) {
            return ResultUtil.error(ResultEnum.SELECT_ERROR);
        }
    }

    @PostMapping("/updateStoreStatus")
    @ResponseBody
    public Object updateStoreStage(@RequestBody StatusVO statusVo) {

        try {
            //更新项目阶段
            //storeDao.updateStoreStage(statusVo.getSource_id(),statusVo.getProject_stage());
            UpdateWrapper updateWrapper=new UpdateWrapper();
            updateWrapper.eq("id",statusVo.getSource_id());
            updateWrapper.set("project_stage",statusVo.getProject_stage());
            storeSerrvice.update(updateWrapper);

            //添加文件附件
            File file=new File();
            file.setStoreId(statusVo.getStore_id());
            file.setSourceId(statusVo.getSource_id());
            file.setSourceType(statusVo.getSource_type());//1项目、2工单预处理,3工单操作,4巡检
            file.setName(statusVo.getName());
            file.setUrl(statusVo.getUrl());
            file.setType(statusVo.getFile_type());
            fileSerrvice.save(file);

            return ResultUtil.success();
        }catch (Exception e) {
            return ResultUtil.error(ResultEnum.SELECT_ERROR);
        }
    }
}