xuhy
8 天以前 f131c141bafa2a060050fa85799fb9d1eb617b69
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package com.ruoyi.web.controller.api;
 
 
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.utils.WebUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.TErpGoodsAddDto;
import com.ruoyi.system.dto.TErpGoodsInfoSaveDto;
import com.ruoyi.system.dto.TErpGoodsUpdateStatusDto;
import com.ruoyi.system.importExcel.TErpGoodsExcel;
import com.ruoyi.system.model.TErpGoods;
import com.ruoyi.system.query.TErpGoodsQuery;
import com.ruoyi.system.service.TErpGoodsService;
import com.ruoyi.system.vo.TErpGoodsVO;
import com.ruoyi.web.controller.tool.ImportExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
 
/**
 * <p>
 * erp商品 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-08-20
 */
@RestController
@RequestMapping("/t-erp-goods")
@Api(tags = "供应商商品管理")
public class TErpGoodsController {
 
 
    private final TErpGoodsService erpGoodsService;
    private final TokenService tokenService;
 
    @Autowired
    public TErpGoodsController(TErpGoodsService erpGoodsService, TokenService tokenService) {
        this.erpGoodsService = erpGoodsService;
        this.tokenService = tokenService;
    }
 
 
 
    /**
     * 获取erp问题上报管理列表
     */
    @ApiOperation(value = "供应商获取商品分页列表")
    @PostMapping(value = "/pageList")
    public R<PageInfo<TErpGoodsVO>> pageList(@RequestBody TErpGoodsQuery query) {
        SysUser user = tokenService.getLoginUser().getUser();
        return R.ok(erpGoodsService.pageList(query,user));
    }
 
 
 
    @ApiOperation(value = "供应商添加商品")
    @PostMapping(value = "/add")
    public R<Boolean> add(@Validated @RequestBody TErpGoodsAddDto dto) {
        SysUser user = tokenService.getLoginUser().getUser();
        if (erpGoodsService.isExit(dto.getGoodsIdCode(), dto.getQuasiNumber())) {
            return R.fail("erp商品已存在");
        }
        TErpGoods goods = new TErpGoods();
        goods.setSupplierClinicId(user.getUserId().toString());
        goods.setCreateId(user.getUserId().toString());
        goods.setGoodsIdCode(dto.getGoodsIdCode());
        goods.setQuasiNumber(dto.getQuasiNumber());
        goods.setManufacturer(dto.getManufacturer());
        goods.setFormulationSpec(dto.getFormulationSpec());
        goods.setPackingSpec(dto.getPackingSpec());
        goods.setGoodsName(dto.getGoodsName());
        return R.ok(erpGoodsService.save(goods));
    }
 
    @ApiOperation(value = "供应商删除商品")
    @DeleteMapping(value = "/delete/{id}")
    public R<Boolean> delete(@PathVariable String id) {
        return R.ok(erpGoodsService.removeById(id));
    }
 
 
    /**
     * 启用 停用
     */
    @ApiOperation(value = "供应商启用 停用商品")
    @PostMapping(value = "/updateStatus")
    public R<Boolean> updateStatus(@RequestBody TErpGoodsUpdateStatusDto dto) {
        TErpGoods goods = erpGoodsService.getById(dto.getId());
        if(dto.getState()==1 && goods.getTypeId()==null){
            return R.fail("操作失败,请先完善商品信息");
        }
        if(dto.getState()==1 && goods.getClinicPurchasePrice()==null){
            return R.fail("操作失败,请设置供应商分佣比例后再启用");
        }
        goods.setState(dto.getState());
        boolean b = erpGoodsService.updateById(goods);
        return R.ok(b);
    }
 
    @ApiOperation(value = "供应商完善商品")
    @PostMapping(value = "/saveDataInfo")
    public R<Boolean> saveDataInfo(@RequestBody @Valid TErpGoodsInfoSaveDto dto) {
        TErpGoods goods = erpGoodsService.getById(dto.getId());
        BeanUtils.copyProperties(dto,goods);
        return R.ok(erpGoodsService.updateById(goods));
    }
 
    @ApiOperation(value = "供应商商品详情")
    @GetMapping(value = "/detail/{id}")
    public R<TErpGoods> detail( @PathVariable String  id) {
        TErpGoods goods = erpGoodsService.getById(id);
        return R.ok(goods);
    }
 
    @ApiOperation(value = "商品管理信息导出--导出")
    @PostMapping("/export")
    public void listExport(@RequestBody TErpGoodsQuery query)
    {
        SysUser user = tokenService.getLoginUser().getUser();
        List<TErpGoodsVO> pageList = erpGoodsService.listExport(query,user);
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TErpGoodsVO.class, pageList);
        HttpServletResponse response = WebUtils.response();
        assert response != null;
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        ServletOutputStream outputStream = null;
        try {
            String fileName = URLEncoder.encode("商品管理信息导出.xls", "utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setHeader("Pragma", "no-cache");
            response.setHeader("Cache-Control", "no-cache");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
 
 
    @ApiOperation(value = "商品管理信息导入")
    @PostMapping("/importFile")
    public AjaxResult importFile(@RequestParam(value = "file") MultipartFile file ) {
 
        SysUser user = tokenService.getLoginUser().getUser();
        JSONObject jsonObject = new JSONObject();
        ImportParams params = new ImportParams();
        params.setHeadRows(1); //表头行数
        String msg = null;
        InputStream inputStream = null;
        TErpGoods goods = new TErpGoods();
        try {
            inputStream = file.getInputStream();
            List<TErpGoodsExcel> carAnnuallyImportExcels = ExcelImportUtil.importExcel(inputStream, TErpGoodsExcel.class, params);
            // 处理车辆数据
            for (TErpGoodsExcel erpGoodsExcel : carAnnuallyImportExcels) {
                System.out.println(erpGoodsExcel);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("车辆年检记录导入失败!");
        }finally {
            try {
                inputStream.close();
            } catch (IOException e) {
                throw new ServiceException(e.getMessage());
            }
        }
        return AjaxResult.success(jsonObject);
 
    }
 
 
}